Skip to content

Commit 55d57ef

Browse files
Wer-Wolfgregkh
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 14c4dc8 commit 55d57ef

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

drivers/misc/eeprom/ee1004.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Copyright (C) 2008 Wolfram Sang, Pengutronix
1010
*/
1111

12+
#include <linux/device.h>
1213
#include <linux/i2c.h>
1314
#include <linux/init.h>
1415
#include <linux/kernel.h>
@@ -207,6 +208,16 @@ static void ee1004_cleanup(int idx, struct ee1004_bus_data *bd)
207208
}
208209
}
209210

211+
static void ee1004_cleanup_bus_data(void *data)
212+
{
213+
struct ee1004_bus_data *bd = data;
214+
215+
/* Remove page select clients if this is the last device */
216+
mutex_lock(&ee1004_bus_lock);
217+
ee1004_cleanup(EE1004_NUM_PAGES, bd);
218+
mutex_unlock(&ee1004_bus_lock);
219+
}
220+
210221
static int ee1004_probe(struct i2c_client *client)
211222
{
212223
struct ee1004_bus_data *bd;
@@ -228,6 +239,10 @@ static int ee1004_probe(struct i2c_client *client)
228239
"Only %d busses supported", EE1004_MAX_BUSSES);
229240
}
230241

242+
err = devm_add_action_or_reset(&client->dev, ee1004_cleanup_bus_data, bd);
243+
if (err < 0)
244+
return err;
245+
231246
i2c_set_clientdata(client, bd);
232247

233248
if (++bd->dev_count == 1) {
@@ -237,16 +252,18 @@ static int ee1004_probe(struct i2c_client *client)
237252

238253
cl = i2c_new_dummy_device(client->adapter, EE1004_ADDR_SET_PAGE + cnr);
239254
if (IS_ERR(cl)) {
240-
err = PTR_ERR(cl);
241-
goto err_clients;
255+
mutex_unlock(&ee1004_bus_lock);
256+
return PTR_ERR(cl);
242257
}
243258
bd->set_page[cnr] = cl;
244259
}
245260

246261
/* Remember current page to avoid unneeded page select */
247262
err = ee1004_get_current_page(bd);
248-
if (err < 0)
249-
goto err_clients;
263+
if (err < 0) {
264+
mutex_unlock(&ee1004_bus_lock);
265+
return err;
266+
}
250267
dev_dbg(&client->dev, "Currently selected page: %d\n", err);
251268
bd->current_page = err;
252269
}
@@ -260,22 +277,6 @@ static int ee1004_probe(struct i2c_client *client)
260277
EE1004_EEPROM_SIZE);
261278

262279
return 0;
263-
264-
err_clients:
265-
ee1004_cleanup(cnr, bd);
266-
mutex_unlock(&ee1004_bus_lock);
267-
268-
return err;
269-
}
270-
271-
static void ee1004_remove(struct i2c_client *client)
272-
{
273-
struct ee1004_bus_data *bd = i2c_get_clientdata(client);
274-
275-
/* Remove page select clients if this is the last device */
276-
mutex_lock(&ee1004_bus_lock);
277-
ee1004_cleanup(EE1004_NUM_PAGES, bd);
278-
mutex_unlock(&ee1004_bus_lock);
279280
}
280281

281282
/*-------------------------------------------------------------------------*/
@@ -286,7 +287,6 @@ static struct i2c_driver ee1004_driver = {
286287
.dev_groups = ee1004_groups,
287288
},
288289
.probe = ee1004_probe,
289-
.remove = ee1004_remove,
290290
.id_table = ee1004_ids,
291291
};
292292
module_i2c_driver(ee1004_driver);

0 commit comments

Comments
 (0)