Skip to contentSkip to conversation

eeprom: at24: last bits of the big refactoring

PATCH In review Bartosz Golaszewski 2 participants 6 messages Apr 11, 2018 – Apr 20, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover eeprom: at24: last bits of the big refactoring

This is a follow-up to the big series merged for 4.17. The patches contain some bits and pieces that were missing in the last submission or depend on some new features merged this merge window.

v1 -> v2:
- dropped patch 1/4 because id_table is still needed as pointed out by Peter Rosin
- fixed patch 3/3: we need to free the dummy client if regmap_init fails

Bartosz Golaszewski (3):
eeprom: at24: use devm_nvmem_register()
eeprom: at24: provide and use a helper for releasing dummy i2c clients
eeprom: at24: provide a separate routine for creating dummy i2c
clients

 drivers/misc/eeprom/at24.c | 71 ++++++++++++++++++++++++--------------
 1 file changed, 46 insertions(+), 25 deletions(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH v2 1/3 eeprom: at24: use devm_nvmem_register()

We now have a managed variant of nvmem_register(). Use it in at24_probe().

---
 drivers/misc/eeprom/at24.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/misc/eeprom/at24.c +1 -3
index 0c125f207aea..02c9dd835547 100644
@@ -685,7 +685,7 @@ static int at24_probe(struct i2c_client *client)
 	nvmem_config.word_size = 1;
 	nvmem_config.size = pdata.byte_len;
 
-	at24->nvmem = nvmem_register(&nvmem_config);
+	at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
 	if (IS_ERR(at24->nvmem)) {
 		err = PTR_ERR(at24->nvmem);
 		goto err_clients;
@@ -718,8 +718,6 @@ static int at24_remove(struct i2c_client *client)
 
 	at24 = i2c_get_clientdata(client);
 
-	nvmem_unregister(at24->nvmem);
-
 	for (i = 1; i < at24->num_addresses; i++)
 		i2c_unregister_device(at24->client[i].client);
 
Signature · 1 line
2.17.0
#2 lore raw

PATCH v2 2/3 eeprom: at24: provide and use a helper for releasing dummy i2c clients

In reply to Bartosz Golaszewski

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().

---
 drivers/misc/eeprom/at24.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/misc/eeprom/at24.c +10 -8
index 02c9dd835547..163ef7bf18e3 100644
@@ -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 @@ 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);
 
Signature · 1 line
2.17.0
#3 lore raw

PATCH v2 3/3 eeprom: at24: provide a separate routine for creating dummy i2c clients

In reply to Bartosz Golaszewski

Move the code responsible for creating the dummy i2c clients used by chips taking multiple slave addresses to a separate function.

---
 drivers/misc/eeprom/at24.c | 49 +++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 14 deletions(-)
drivers/misc/eeprom/at24.c +35 -14
index 163ef7bf18e3..b00e2b5c47e8 100644
@@ -540,6 +540,37 @@ static void at24_remove_dummy_clients(struct at24_data *at24)
 		i2c_unregister_device(at24->client[i].client);
 }
 
+static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
+				  struct regmap_config *regmap_config)
+{
+	struct i2c_client *base_client, *dummy_client;
+	unsigned short int addr;
+	struct regmap *regmap;
+	struct device *dev;
+
+	base_client = at24->client[0].client;
+	dev = &base_client->dev;
+	addr = base_client->addr + index;
+
+	dummy_client = i2c_new_dummy(base_client->adapter,
+				     base_client->addr + index);
+	if (!dummy_client) {
+		dev_err(dev, "address 0x%02x unavailable\n", addr);
+		return -EADDRINUSE;
+	}
+
+	regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
+	if (IS_ERR(regmap)) {
+		i2c_unregister_device(dummy_client);
+		return PTR_ERR(regmap);
+	}
+
+	at24->client[index].client = dummy_client;
+	at24->client[index].regmap = regmap;
+
+	return 0;
+}
+
 static unsigned int at24_get_offset_adj(u8 flags, unsigned int byte_len)
 {
 	if (flags & AT24_FLAG_MAC) {
@@ -645,20 +676,10 @@ static int at24_probe(struct i2c_client *client)
 
 	/* use dummy devices for multiple-address chips */
 	for (i = 1; i < num_addresses; i++) {
-		at24->client[i].client = i2c_new_dummy(client->adapter,
-						       client->addr + i);
-		if (!at24->client[i].client) {
-			dev_err(dev, "address 0x%02x unavailable\n",
-				client->addr + i);
-			err = -EADDRINUSE;
-			goto err_clients;
-		}
-		at24->client[i].regmap = devm_regmap_init_i2c(
-						at24->client[i].client,
-						&regmap_config);
-		if (IS_ERR(at24->client[i].regmap)) {
-			err = PTR_ERR(at24->client[i].regmap);
-			goto err_clients;
+		err = at24_make_dummy_client(at24, i, &regmap_config);
+		if (err) {
+			at24_remove_dummy_clients(at24);
+			return err;
 		}
 	}
 
Signature · 1 line
2.17.0
Reviewed-by on the v2 series
#4 lore raw
In reply to Bartosz Golaszewski
Quoted 9 lines · Bartosz Golaszewski

This is a follow-up to the big series merged for 4.17. The patches contain some bits and pieces that were missing in the last submission or depend on some new features merged this merge window.

v1 -> v2:
- dropped patch 1/4 because id_table is still needed as pointed out by Peter Rosin
- fixed patch 3/3: we need to free the dummy client if regmap_init fails

Quoted 5 lines

Bartosz Golaszewski (3):
eeprom: at24: use devm_nvmem_register()
eeprom: at24: provide and use a helper for releasing dummy i2c clients
eeprom: at24: provide a separate routine for creating dummy i2c
clients

For all three:

Cheers,
Peter

author Applied
#5 lore raw

2018-04-12 17:08 GMT+02:00 Peter Rosin <[email protected]>:

Quoted 16 lines · Bartosz Golaszewski
Quoted 9 lines

This is a follow-up to the big series merged for 4.17. The patches contain some bits and pieces that were missing in the last submission or depend on some new features merged this merge window.

v1 -> v2:
- dropped patch 1/4 because id_table is still needed as pointed out by Peter Rosin
- fixed patch 3/3: we need to free the dummy client if regmap_init fails

Quoted 5 lines

Bartosz Golaszewski (3):
eeprom: at24: use devm_nvmem_register()
eeprom: at24: provide and use a helper for releasing dummy i2c clients
eeprom: at24: provide a separate routine for creating dummy i2c
clients

Quoted 6 lines

For all three:

Cheers,
Peter

Applied to at24/for-next.