Skip to content

Commit fe45d12

Browse files
bbkzzdtor
authored andcommitted
Input: lm8323 - convert to use devm_* api
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources. Signed-off-by: Yangtao Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 0410595 commit fe45d12

File tree

1 file changed

+26
-51
lines changed

1 file changed

+26
-51
lines changed

drivers/input/keyboard/lm8323.c

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
556556
const char *name)
557557
{
558558
struct lm8323_pwm *pwm;
559+
int err;
559560

560561
BUG_ON(id > 3);
561562

@@ -575,18 +576,18 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
575576
pwm->cdev.name = name;
576577
pwm->cdev.brightness_set = lm8323_pwm_set_brightness;
577578
pwm->cdev.groups = lm8323_pwm_groups;
578-
if (led_classdev_register(dev, &pwm->cdev) < 0) {
579-
dev_err(dev, "couldn't register PWM %d\n", id);
580-
return -1;
579+
580+
err = devm_led_classdev_register(dev, &pwm->cdev);
581+
if (err) {
582+
dev_err(dev, "couldn't register PWM %d: %d\n", id, err);
583+
return err;
581584
}
582585
pwm->enabled = true;
583586
}
584587

585588
return 0;
586589
}
587590

588-
static struct i2c_driver lm8323_i2c_driver;
589-
590591
static ssize_t lm8323_show_disable(struct device *dev,
591592
struct device_attribute *attr, char *buf)
592593
{
@@ -648,12 +649,13 @@ static int lm8323_probe(struct i2c_client *client)
648649
return -EINVAL;
649650
}
650651

651-
lm = kzalloc(sizeof *lm, GFP_KERNEL);
652-
idev = input_allocate_device();
653-
if (!lm || !idev) {
654-
err = -ENOMEM;
655-
goto fail1;
656-
}
652+
lm = devm_kzalloc(&client->dev, sizeof(*lm), GFP_KERNEL);
653+
if (!lm)
654+
return -ENOMEM;
655+
656+
idev = devm_input_allocate_device(&client->dev);
657+
if (!idev)
658+
return -ENOMEM;
657659

658660
lm->client = client;
659661
lm->idev = idev;
@@ -669,8 +671,10 @@ static int lm8323_probe(struct i2c_client *client)
669671

670672
lm8323_reset(lm);
671673

672-
/* Nothing's set up to service the IRQ yet, so just spin for max.
673-
* 100ms until we can configure. */
674+
/*
675+
* Nothing's set up to service the IRQ yet, so just spin for max.
676+
* 100ms until we can configure.
677+
*/
674678
tmo = jiffies + msecs_to_jiffies(100);
675679
while (lm8323_read(lm, LM8323_CMD_READ_INT, data, 1) == 1) {
676680
if (data[0] & INT_NOINIT)
@@ -690,15 +694,14 @@ static int lm8323_probe(struct i2c_client *client)
690694
/* If a true probe check the device */
691695
if (lm8323_read_id(lm, data) != 0) {
692696
dev_err(&client->dev, "device not found\n");
693-
err = -ENODEV;
694-
goto fail1;
697+
return -ENODEV;
695698
}
696699

697700
for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) {
698701
err = init_pwm(lm, pwm + 1, &client->dev,
699702
pdata->pwm_names[pwm]);
700-
if (err < 0)
701-
goto fail2;
703+
if (err)
704+
return err;
702705
}
703706

704707
lm->kp_enabled = true;
@@ -722,14 +725,16 @@ static int lm8323_probe(struct i2c_client *client)
722725
err = input_register_device(idev);
723726
if (err) {
724727
dev_dbg(&client->dev, "error registering input device\n");
725-
goto fail2;
728+
return err;
726729
}
727730

728-
err = request_threaded_irq(client->irq, NULL, lm8323_irq,
729-
IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm);
731+
err = devm_request_threaded_irq(&client->dev, client->irq,
732+
NULL, lm8323_irq,
733+
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
734+
"lm8323", lm);
730735
if (err) {
731736
dev_err(&client->dev, "could not get IRQ %d\n", client->irq);
732-
goto fail3;
737+
return err;
733738
}
734739

735740
i2c_set_clientdata(client, lm);
@@ -738,35 +743,6 @@ static int lm8323_probe(struct i2c_client *client)
738743
enable_irq_wake(client->irq);
739744

740745
return 0;
741-
742-
fail3:
743-
input_unregister_device(idev);
744-
idev = NULL;
745-
fail2:
746-
while (--pwm >= 0)
747-
if (lm->pwm[pwm].enabled)
748-
led_classdev_unregister(&lm->pwm[pwm].cdev);
749-
fail1:
750-
input_free_device(idev);
751-
kfree(lm);
752-
return err;
753-
}
754-
755-
static void lm8323_remove(struct i2c_client *client)
756-
{
757-
struct lm8323_chip *lm = i2c_get_clientdata(client);
758-
int i;
759-
760-
disable_irq_wake(client->irq);
761-
free_irq(client->irq, lm);
762-
763-
input_unregister_device(lm->idev);
764-
765-
for (i = 0; i < 3; i++)
766-
if (lm->pwm[i].enabled)
767-
led_classdev_unregister(&lm->pwm[i].cdev);
768-
769-
kfree(lm);
770746
}
771747

772748
/*
@@ -827,7 +803,6 @@ static struct i2c_driver lm8323_i2c_driver = {
827803
.dev_groups = lm8323_groups,
828804
},
829805
.probe = lm8323_probe,
830-
.remove = lm8323_remove,
831806
.id_table = lm8323_id,
832807
};
833808
MODULE_DEVICE_TABLE(i2c, lm8323_id);

0 commit comments

Comments
 (0)