Skip to contentSkip to conversation

eeprom: ee1004: Use devres for bus data cleanup

PATCH New Armin Wolf 1 participant 2 messages Jun 25, 2024 Char and misc drivers

lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

PATCH 1/2 eeprom: ee1004: Use devres for bus data cleanup

Use devm_add_action_or_reset() to clean up the bus data at driver removal or when an error occurs during probe. This will allow us to use other devres-based APIs later.

Tested on a Dell Inspiron 3505.

---
 drivers/misc/eeprom/ee1004.c | 42 ++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/misc/eeprom/ee1004.c +21 -21
index bf4f65dc6d9a..b1f760cc3be0 100644
@@ -9,6 +9,7 @@
  * Copyright (C) 2008 Wolfram Sang, Pengutronix
  */
 
+#include <linux/device.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -207,6 +208,16 @@ static void ee1004_cleanup(int idx, struct ee1004_bus_data *bd)
 	}
 }
 
+static void ee1004_cleanup_bus_data(void *data)
+{
+	struct ee1004_bus_data *bd = data;
+
+	/* Remove page select clients if this is the last device */
+	mutex_lock(&ee1004_bus_lock);
+	ee1004_cleanup(EE1004_NUM_PAGES, bd);
+	mutex_unlock(&ee1004_bus_lock);
+}
+
 static int ee1004_probe(struct i2c_client *client)
 {
 	struct ee1004_bus_data *bd;
@@ -228,6 +239,10 @@ static int ee1004_probe(struct i2c_client *client)
 				     "Only %d busses supported", EE1004_MAX_BUSSES);
 	}
 
+	err = devm_add_action_or_reset(&client->dev, ee1004_cleanup_bus_data, bd);
+	if (err < 0)
+		return err;
+
 	i2c_set_clientdata(client, bd);
 
 	if (++bd->dev_count == 1) {
@@ -237,16 +252,18 @@ static int ee1004_probe(struct i2c_client *client)
 
 			cl = i2c_new_dummy_device(client->adapter, EE1004_ADDR_SET_PAGE + cnr);
 			if (IS_ERR(cl)) {
-				err = PTR_ERR(cl);
-				goto err_clients;
+				mutex_unlock(&ee1004_bus_lock);
+				return PTR_ERR(cl);
 			}
 			bd->set_page[cnr] = cl;
 		}
 
 		/* Remember current page to avoid unneeded page select */
 		err = ee1004_get_current_page(bd);
-		if (err < 0)
-			goto err_clients;
+		if (err < 0) {
+			mutex_unlock(&ee1004_bus_lock);
+			return err;
+		}
 		dev_dbg(&client->dev, "Currently selected page: %d\n", err);
 		bd->current_page = err;
 	}
@@ -260,22 +277,6 @@ static int ee1004_probe(struct i2c_client *client)
 		 EE1004_EEPROM_SIZE);
 
 	return 0;
-
- err_clients:
-	ee1004_cleanup(cnr, bd);
-	mutex_unlock(&ee1004_bus_lock);
-
-	return err;
-}
-
-static void ee1004_remove(struct i2c_client *client)
-{
-	struct ee1004_bus_data *bd = i2c_get_clientdata(client);
-
-	/* Remove page select clients if this is the last device */
-	mutex_lock(&ee1004_bus_lock);
-	ee1004_cleanup(EE1004_NUM_PAGES, bd);
-	mutex_unlock(&ee1004_bus_lock);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -286,7 +287,6 @@ static struct i2c_driver ee1004_driver = {
 		.dev_groups = ee1004_groups,
 	},
 	.probe = ee1004_probe,
-	.remove = ee1004_remove,
 	.id_table = ee1004_ids,
 };
 module_i2c_driver(ee1004_driver);

--
2.39.2

author
#1 lore raw

PATCH 2/2 eeprom: ee1004: Add nvmem support

Currently the driver does not register a nvmem provider, which means that userspace programs cannot access the ee1004 EEPROM through the standard nvmem sysfs API.
Fix this by replacing the custom sysfs attribute with a standard nvmem interface, which also takes care of backwards compatibility.

Tested on a Dell Inspiron 3505.

---
 drivers/misc/eeprom/Kconfig  |  2 ++
 drivers/misc/eeprom/ee1004.c | 58 +++++++++++++++++++++++-------------
 2 files changed, 40 insertions(+), 20 deletions(-)
drivers/misc/eeprom/Kconfig +2 -0
index 4e61ac18cc96..9df12399bda3 100644
@@ -109,6 +109,8 @@ config EEPROM_IDT_89HPESX
 config EEPROM_EE1004
 	tristate "SPD EEPROMs on DDR4 memory modules"
 	depends on I2C && SYSFS
+	select NVMEM
+	select NVMEM_SYSFS
 	help
 	  Enable this driver to get read support to SPD EEPROMs following
 	  the JEDEC EE1004 standard. These are typically found on DDR4
drivers/misc/eeprom/ee1004.c +38 -20

105 lines not on this page · raw message

--
2.39.2