@@ -439,13 +439,11 @@ static int bma150_initialize(struct bma150_data *bma150,
439
439
return bma150_set_mode (bma150 , BMA150_MODE_SLEEP );
440
440
}
441
441
442
- static void bma150_init_input_device (struct bma150_data * bma150 ,
443
- struct input_dev * idev )
442
+ static void bma150_init_input_device (struct input_dev * idev )
444
443
{
445
444
idev -> name = BMA150_DRIVER ;
446
445
idev -> phys = BMA150_DRIVER "/input0" ;
447
446
idev -> id .bustype = BUS_I2C ;
448
- idev -> dev .parent = & bma150 -> client -> dev ;
449
447
450
448
idev -> evbit [0 ] = BIT_MASK (EV_ABS );
451
449
input_set_abs_params (idev , ABS_X , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
@@ -458,11 +456,11 @@ static int bma150_register_input_device(struct bma150_data *bma150)
458
456
struct input_dev * idev ;
459
457
int error ;
460
458
461
- idev = input_allocate_device ( );
459
+ idev = devm_input_allocate_device ( & bma150 -> client -> dev );
462
460
if (!idev )
463
461
return - ENOMEM ;
464
462
465
- bma150_init_input_device (bma150 , idev );
463
+ bma150_init_input_device (idev );
466
464
467
465
idev -> open = bma150_irq_open ;
468
466
idev -> close = bma150_irq_close ;
@@ -471,10 +469,8 @@ static int bma150_register_input_device(struct bma150_data *bma150)
471
469
bma150 -> input = idev ;
472
470
473
471
error = input_register_device (idev );
474
- if (error ) {
475
- input_free_device (idev );
472
+ if (error )
476
473
return error ;
477
- }
478
474
479
475
return 0 ;
480
476
}
@@ -484,7 +480,7 @@ static int bma150_register_polled_device(struct bma150_data *bma150)
484
480
struct input_polled_dev * ipoll_dev ;
485
481
int error ;
486
482
487
- ipoll_dev = input_allocate_polled_device ( );
483
+ ipoll_dev = devm_input_allocate_polled_device ( & bma150 -> client -> dev );
488
484
if (!ipoll_dev )
489
485
return - ENOMEM ;
490
486
@@ -496,16 +492,14 @@ static int bma150_register_polled_device(struct bma150_data *bma150)
496
492
ipoll_dev -> poll_interval_min = BMA150_POLL_MIN ;
497
493
ipoll_dev -> poll_interval_max = BMA150_POLL_MAX ;
498
494
499
- bma150_init_input_device (bma150 , ipoll_dev -> input );
495
+ bma150_init_input_device (ipoll_dev -> input );
500
496
501
497
bma150 -> input_polled = ipoll_dev ;
502
498
bma150 -> input = ipoll_dev -> input ;
503
499
504
500
error = input_register_polled_device (ipoll_dev );
505
- if (error ) {
506
- input_free_polled_device (ipoll_dev );
501
+ if (error )
507
502
return error ;
508
- }
509
503
510
504
return 0 ;
511
505
}
@@ -531,7 +525,7 @@ static int bma150_probe(struct i2c_client *client,
531
525
return - EINVAL ;
532
526
}
533
527
534
- bma150 = kzalloc ( sizeof (struct bma150_data ), GFP_KERNEL );
528
+ bma150 = devm_kzalloc ( & client -> dev , sizeof (* bma150 ), GFP_KERNEL );
535
529
if (!bma150 )
536
530
return - ENOMEM ;
537
531
@@ -544,7 +538,7 @@ static int bma150_probe(struct i2c_client *client,
544
538
dev_err (& client -> dev ,
545
539
"IRQ GPIO conf. error %d, error %d\n" ,
546
540
client -> irq , error );
547
- goto err_free_mem ;
541
+ return error ;
548
542
}
549
543
}
550
544
cfg = & pdata -> cfg ;
@@ -554,57 +548,40 @@ static int bma150_probe(struct i2c_client *client,
554
548
555
549
error = bma150_initialize (bma150 , cfg );
556
550
if (error )
557
- goto err_free_mem ;
551
+ return error ;
558
552
559
553
if (client -> irq > 0 ) {
560
554
error = bma150_register_input_device (bma150 );
561
555
if (error )
562
- goto err_free_mem ;
556
+ return error ;
563
557
564
- error = request_threaded_irq ( client -> irq ,
558
+ error = devm_request_threaded_irq ( & client -> dev , client -> irq ,
565
559
NULL , bma150_irq_thread ,
566
560
IRQF_TRIGGER_RISING | IRQF_ONESHOT ,
567
561
BMA150_DRIVER , bma150 );
568
562
if (error ) {
569
563
dev_err (& client -> dev ,
570
564
"irq request failed %d, error %d\n" ,
571
565
client -> irq , error );
572
- input_unregister_device (bma150 -> input );
573
- goto err_free_mem ;
566
+ return error ;
574
567
}
575
568
} else {
576
569
error = bma150_register_polled_device (bma150 );
577
570
if (error )
578
- goto err_free_mem ;
571
+ return error ;
579
572
}
580
573
581
574
i2c_set_clientdata (client , bma150 );
582
575
583
576
pm_runtime_enable (& client -> dev );
584
577
585
578
return 0 ;
586
-
587
- err_free_mem :
588
- kfree (bma150 );
589
- return error ;
590
579
}
591
580
592
581
static int bma150_remove (struct i2c_client * client )
593
582
{
594
- struct bma150_data * bma150 = i2c_get_clientdata (client );
595
-
596
583
pm_runtime_disable (& client -> dev );
597
584
598
- if (client -> irq > 0 ) {
599
- free_irq (client -> irq , bma150 );
600
- input_unregister_device (bma150 -> input );
601
- } else {
602
- input_unregister_polled_device (bma150 -> input_polled );
603
- input_free_polled_device (bma150 -> input_polled );
604
- }
605
-
606
- kfree (bma150 );
607
-
608
585
return 0 ;
609
586
}
610
587
0 commit comments