Skip to content

Commit

Permalink
eeprom: at24: provide and use a helper for releasing dummy i2c clients
Browse files Browse the repository at this point in the history
This allows us to drop two opencoded for loops. We also don't need to
check if the i2c client is NULL before calling i2c_unregister_device().

Signed-off-by: Bartosz Golaszewski <[email protected]>
Reviewed-by: Peter Rosin <[email protected]>
  • Loading branch information
brgl committed May 16, 2018
1 parent bbe6984 commit 39933e0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/misc/eeprom/at24.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ static int at24_get_pdata(struct device *dev, struct at24_platform_data *pdata)
return 0;
}

static void at24_remove_dummy_clients(struct at24_data *at24)
{
int i;

for (i = 1; i < at24->num_addresses; i++)
i2c_unregister_device(at24->client[i].client);
}

static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len)
{
if (flags & AT24_FLAG_MAC) {
Expand Down Expand Up @@ -702,10 +710,7 @@ static int at24_probe(struct i2c_client *client)
return 0;

err_clients:
for (i = 1; i < num_addresses; i++)
if (at24->client[i].client)
i2c_unregister_device(at24->client[i].client);

at24_remove_dummy_clients(at24);
pm_runtime_disable(dev);

return err;
Expand All @@ -714,13 +719,10 @@ static int at24_probe(struct i2c_client *client)
static int at24_remove(struct i2c_client *client)
{
struct at24_data *at24;
int i;

at24 = i2c_get_clientdata(client);

for (i = 1; i < at24->num_addresses; i++)
i2c_unregister_device(at24->client[i].client);

at24_remove_dummy_clients(at24);
pm_runtime_disable(&client->dev);
pm_runtime_set_suspended(&client->dev);

Expand Down

0 comments on commit 39933e0

Please sign in to comment.