@@ -239,7 +239,7 @@ static int qt2160_write(struct i2c_client *client, u8 reg, u8 data)
239
239
static int qt2160_register_leds (struct qt2160_data * qt2160 )
240
240
{
241
241
struct i2c_client * client = qt2160 -> client ;
242
- int ret ;
242
+ int error ;
243
243
int i ;
244
244
245
245
for (i = 0 ; i < QT2160_NUM_LEDS_X ; i ++ ) {
@@ -252,9 +252,9 @@ static int qt2160_register_leds(struct qt2160_data *qt2160)
252
252
led -> id = i ;
253
253
led -> qt2160 = qt2160 ;
254
254
255
- ret = led_classdev_register (& client -> dev , & led -> cdev );
256
- if (ret < 0 )
257
- return ret ;
255
+ error = devm_led_classdev_register (& client -> dev , & led -> cdev );
256
+ if (error )
257
+ return error ;
258
258
}
259
259
260
260
/* Tur off LEDs */
@@ -265,25 +265,13 @@ static int qt2160_register_leds(struct qt2160_data *qt2160)
265
265
return 0 ;
266
266
}
267
267
268
- static void qt2160_unregister_leds (struct qt2160_data * qt2160 )
269
- {
270
- int i ;
271
-
272
- for (i = 0 ; i < QT2160_NUM_LEDS_X ; i ++ )
273
- led_classdev_unregister (& qt2160 -> leds [i ].cdev );
274
- }
275
-
276
268
#else
277
269
278
270
static inline int qt2160_register_leds (struct qt2160_data * qt2160 )
279
271
{
280
272
return 0 ;
281
273
}
282
274
283
- static inline void qt2160_unregister_leds (struct qt2160_data * qt2160 )
284
- {
285
- }
286
-
287
275
#endif
288
276
289
277
static bool qt2160_identify (struct i2c_client * client )
@@ -334,13 +322,13 @@ static int qt2160_probe(struct i2c_client *client)
334
322
return - ENODEV ;
335
323
336
324
/* Chip is valid and active. Allocate structure */
337
- qt2160 = kzalloc ( sizeof (struct qt2160_data ), GFP_KERNEL );
338
- input = input_allocate_device ();
339
- if (! qt2160 || ! input ) {
340
- dev_err ( & client -> dev , "insufficient memory\n" );
341
- error = - ENOMEM ;
342
- goto err_free_mem ;
343
- }
325
+ qt2160 = devm_kzalloc ( & client -> dev , sizeof (* qt2160 ), GFP_KERNEL );
326
+ if (! qt2160 )
327
+ return - ENOMEM ;
328
+
329
+ input = devm_input_allocate_device ( & client -> dev ) ;
330
+ if (! input )
331
+ return - ENOMEM ;
344
332
345
333
qt2160 -> client = client ;
346
334
qt2160 -> input = input ;
@@ -366,66 +354,42 @@ static int qt2160_probe(struct i2c_client *client)
366
354
error = qt2160_write (client , QT2160_CMD_CALIBRATE , 1 );
367
355
if (error ) {
368
356
dev_err (& client -> dev , "failed to calibrate device\n" );
369
- goto err_free_mem ;
357
+ return error ;
370
358
}
371
359
372
360
if (client -> irq ) {
373
- error = request_threaded_irq (client -> irq , NULL , qt2160_irq ,
374
- IRQF_ONESHOT , "qt2160" , input );
361
+ error = devm_request_threaded_irq (& client -> dev , client -> irq ,
362
+ NULL , qt2160_irq ,
363
+ IRQF_ONESHOT ,
364
+ "qt2160" , input );
375
365
if (error ) {
376
366
dev_err (& client -> dev ,
377
367
"failed to allocate irq %d\n" , client -> irq );
378
- goto err_free_mem ;
368
+ return error ;
379
369
}
380
370
} else {
381
371
error = input_setup_polling (input , qt2160_get_key_matrix );
382
372
if (error ) {
383
373
dev_err (& client -> dev , "Failed to setup polling\n" );
384
- goto err_free_mem ;
374
+ return error ;
385
375
}
386
376
input_set_poll_interval (input , QT2160_CYCLE_INTERVAL );
387
377
}
388
378
389
379
error = qt2160_register_leds (qt2160 );
390
380
if (error ) {
391
381
dev_err (& client -> dev , "Failed to register leds\n" );
392
- goto err_free_irq ;
382
+ return error ;
393
383
}
394
384
395
385
error = input_register_device (qt2160 -> input );
396
386
if (error ) {
397
387
dev_err (& client -> dev ,
398
388
"Failed to register input device\n" );
399
- goto err_unregister_leds ;
389
+ return error ;
400
390
}
401
391
402
- i2c_set_clientdata (client , qt2160 );
403
-
404
392
return 0 ;
405
-
406
- err_unregister_leds :
407
- qt2160_unregister_leds (qt2160 );
408
- err_free_irq :
409
- if (client -> irq )
410
- free_irq (client -> irq , qt2160 );
411
- err_free_mem :
412
- input_free_device (input );
413
- kfree (qt2160 );
414
- return error ;
415
- }
416
-
417
- static void qt2160_remove (struct i2c_client * client )
418
- {
419
- struct qt2160_data * qt2160 = i2c_get_clientdata (client );
420
-
421
- qt2160_unregister_leds (qt2160 );
422
-
423
- /* Release IRQ so no queue will be scheduled */
424
- if (client -> irq )
425
- free_irq (client -> irq , qt2160 );
426
-
427
- input_unregister_device (qt2160 -> input );
428
- kfree (qt2160 );
429
393
}
430
394
431
395
static const struct i2c_device_id qt2160_idtable [] = {
@@ -442,7 +406,6 @@ static struct i2c_driver qt2160_driver = {
442
406
443
407
.id_table = qt2160_idtable ,
444
408
.probe = qt2160_probe ,
445
- .remove = qt2160_remove ,
446
409
};
447
410
448
411
module_i2c_driver (qt2160_driver );
0 commit comments