9
9
* Copyright (C) 2008 Wolfram Sang, Pengutronix
10
10
*/
11
11
12
+ #include <linux/device.h>
12
13
#include <linux/i2c.h>
13
14
#include <linux/init.h>
14
15
#include <linux/kernel.h>
@@ -207,6 +208,16 @@ static void ee1004_cleanup(int idx, struct ee1004_bus_data *bd)
207
208
}
208
209
}
209
210
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
+
210
221
static int ee1004_probe (struct i2c_client * client )
211
222
{
212
223
struct ee1004_bus_data * bd ;
@@ -228,6 +239,10 @@ static int ee1004_probe(struct i2c_client *client)
228
239
"Only %d busses supported" , EE1004_MAX_BUSSES );
229
240
}
230
241
242
+ err = devm_add_action_or_reset (& client -> dev , ee1004_cleanup_bus_data , bd );
243
+ if (err < 0 )
244
+ return err ;
245
+
231
246
i2c_set_clientdata (client , bd );
232
247
233
248
if (++ bd -> dev_count == 1 ) {
@@ -237,16 +252,18 @@ static int ee1004_probe(struct i2c_client *client)
237
252
238
253
cl = i2c_new_dummy_device (client -> adapter , EE1004_ADDR_SET_PAGE + cnr );
239
254
if (IS_ERR (cl )) {
240
- err = PTR_ERR ( cl );
241
- goto err_clients ;
255
+ mutex_unlock ( & ee1004_bus_lock );
256
+ return PTR_ERR ( cl ) ;
242
257
}
243
258
bd -> set_page [cnr ] = cl ;
244
259
}
245
260
246
261
/* Remember current page to avoid unneeded page select */
247
262
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
+ }
250
267
dev_dbg (& client -> dev , "Currently selected page: %d\n" , err );
251
268
bd -> current_page = err ;
252
269
}
@@ -260,22 +277,6 @@ static int ee1004_probe(struct i2c_client *client)
260
277
EE1004_EEPROM_SIZE );
261
278
262
279
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 );
279
280
}
280
281
281
282
/*-------------------------------------------------------------------------*/
@@ -286,7 +287,6 @@ static struct i2c_driver ee1004_driver = {
286
287
.dev_groups = ee1004_groups ,
287
288
},
288
289
.probe = ee1004_probe ,
289
- .remove = ee1004_remove ,
290
290
.id_table = ee1004_ids ,
291
291
};
292
292
module_i2c_driver (ee1004_driver );
0 commit comments