summaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorArmin Wolf <W_Armin@gmx.de>2024-06-25 08:34:58 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-07-04 12:02:56 +0200
commit55d57ef6fa97ca631d393cccc641cbe1b16cc382 (patch)
tree72793958076b89ce9ae5829442f999fd839477d5 /drivers/misc
parentMerge tag 'iio-for-6.11b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/g... (diff)
downloadlinux-55d57ef6fa97ca631d393cccc641cbe1b16cc382.tar.xz
linux-55d57ef6fa97ca631d393cccc641cbe1b16cc382.zip
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. Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://lore.kernel.org/r/20240625063459.429953-1-W_Armin@gmx.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/eeprom/ee1004.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c
index bf4f65dc6d9a..b1f760cc3be0 100644
--- a/drivers/misc/eeprom/ee1004.c
+++ b/drivers/misc/eeprom/ee1004.c
@@ -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);