summaryrefslogtreecommitdiff
path: root/drivers/misc/eeprom
diff options
context:
space:
mode:
authorBartosz Golaszewski <brgl@bgdev.pl>2018-03-21 17:29:40 +0100
committerBartosz Golaszewski <brgl@bgdev.pl>2018-05-16 14:42:46 +0200
commit39933e0fd501791bda9393c78ed0aece2188acf2 (patch)
treeb30935805a7241c95fe7be69dadb3bc26ac4358e /drivers/misc/eeprom
parentbbe69841bdfa86333b39cf7a5c7d7273b5324143 (diff)
eeprom: at24: provide and use a helper for releasing dummy i2c clients
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 <brgl@bgdev.pl> Reviewed-by: Peter Rosin <peda@axentia.se>
Diffstat (limited to 'drivers/misc/eeprom')
-rw-r--r--drivers/misc/eeprom/at24.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 5072c6d0fa61..4819e2df591d 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -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) {
@@ -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;
@@ -714,13 +719,10 @@ err_clients:
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);