Commit fe45d127 authored by Yangtao Li's avatar Yangtao Li Committed by Dmitry Torokhov

Input: lm8323 - convert to use devm_* api

Use devm_* api to simplify code, this makes it unnecessary to explicitly
release resources.
Signed-off-by: default avatarYangtao Li <frank.li@vivo.com>
Link: https://lore.kernel.org/r/20230724052901.350240-2-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 0410595e
...@@ -556,6 +556,7 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, ...@@ -556,6 +556,7 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
const char *name) const char *name)
{ {
struct lm8323_pwm *pwm; struct lm8323_pwm *pwm;
int err;
BUG_ON(id > 3); BUG_ON(id > 3);
...@@ -575,9 +576,11 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, ...@@ -575,9 +576,11 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
pwm->cdev.name = name; pwm->cdev.name = name;
pwm->cdev.brightness_set = lm8323_pwm_set_brightness; pwm->cdev.brightness_set = lm8323_pwm_set_brightness;
pwm->cdev.groups = lm8323_pwm_groups; pwm->cdev.groups = lm8323_pwm_groups;
if (led_classdev_register(dev, &pwm->cdev) < 0) {
dev_err(dev, "couldn't register PWM %d\n", id); err = devm_led_classdev_register(dev, &pwm->cdev);
return -1; if (err) {
dev_err(dev, "couldn't register PWM %d: %d\n", id, err);
return err;
} }
pwm->enabled = true; pwm->enabled = true;
} }
...@@ -585,8 +588,6 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, ...@@ -585,8 +588,6 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
return 0; return 0;
} }
static struct i2c_driver lm8323_i2c_driver;
static ssize_t lm8323_show_disable(struct device *dev, static ssize_t lm8323_show_disable(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -648,12 +649,13 @@ static int lm8323_probe(struct i2c_client *client) ...@@ -648,12 +649,13 @@ static int lm8323_probe(struct i2c_client *client)
return -EINVAL; return -EINVAL;
} }
lm = kzalloc(sizeof *lm, GFP_KERNEL); lm = devm_kzalloc(&client->dev, sizeof(*lm), GFP_KERNEL);
idev = input_allocate_device(); if (!lm)
if (!lm || !idev) { return -ENOMEM;
err = -ENOMEM;
goto fail1; idev = devm_input_allocate_device(&client->dev);
} if (!idev)
return -ENOMEM;
lm->client = client; lm->client = client;
lm->idev = idev; lm->idev = idev;
...@@ -669,8 +671,10 @@ static int lm8323_probe(struct i2c_client *client) ...@@ -669,8 +671,10 @@ static int lm8323_probe(struct i2c_client *client)
lm8323_reset(lm); lm8323_reset(lm);
/* Nothing's set up to service the IRQ yet, so just spin for max. /*
* 100ms until we can configure. */ * Nothing's set up to service the IRQ yet, so just spin for max.
* 100ms until we can configure.
*/
tmo = jiffies + msecs_to_jiffies(100); tmo = jiffies + msecs_to_jiffies(100);
while (lm8323_read(lm, LM8323_CMD_READ_INT, data, 1) == 1) { while (lm8323_read(lm, LM8323_CMD_READ_INT, data, 1) == 1) {
if (data[0] & INT_NOINIT) if (data[0] & INT_NOINIT)
...@@ -690,15 +694,14 @@ static int lm8323_probe(struct i2c_client *client) ...@@ -690,15 +694,14 @@ static int lm8323_probe(struct i2c_client *client)
/* If a true probe check the device */ /* If a true probe check the device */
if (lm8323_read_id(lm, data) != 0) { if (lm8323_read_id(lm, data) != 0) {
dev_err(&client->dev, "device not found\n"); dev_err(&client->dev, "device not found\n");
err = -ENODEV; return -ENODEV;
goto fail1;
} }
for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) { for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) {
err = init_pwm(lm, pwm + 1, &client->dev, err = init_pwm(lm, pwm + 1, &client->dev,
pdata->pwm_names[pwm]); pdata->pwm_names[pwm]);
if (err < 0) if (err)
goto fail2; return err;
} }
lm->kp_enabled = true; lm->kp_enabled = true;
...@@ -722,14 +725,16 @@ static int lm8323_probe(struct i2c_client *client) ...@@ -722,14 +725,16 @@ static int lm8323_probe(struct i2c_client *client)
err = input_register_device(idev); err = input_register_device(idev);
if (err) { if (err) {
dev_dbg(&client->dev, "error registering input device\n"); dev_dbg(&client->dev, "error registering input device\n");
goto fail2; return err;
} }
err = request_threaded_irq(client->irq, NULL, lm8323_irq, err = devm_request_threaded_irq(&client->dev, client->irq,
IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm); NULL, lm8323_irq,
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"lm8323", lm);
if (err) { if (err) {
dev_err(&client->dev, "could not get IRQ %d\n", client->irq); dev_err(&client->dev, "could not get IRQ %d\n", client->irq);
goto fail3; return err;
} }
i2c_set_clientdata(client, lm); i2c_set_clientdata(client, lm);
...@@ -738,35 +743,6 @@ static int lm8323_probe(struct i2c_client *client) ...@@ -738,35 +743,6 @@ static int lm8323_probe(struct i2c_client *client)
enable_irq_wake(client->irq); enable_irq_wake(client->irq);
return 0; return 0;
fail3:
input_unregister_device(idev);
idev = NULL;
fail2:
while (--pwm >= 0)
if (lm->pwm[pwm].enabled)
led_classdev_unregister(&lm->pwm[pwm].cdev);
fail1:
input_free_device(idev);
kfree(lm);
return err;
}
static void lm8323_remove(struct i2c_client *client)
{
struct lm8323_chip *lm = i2c_get_clientdata(client);
int i;
disable_irq_wake(client->irq);
free_irq(client->irq, lm);
input_unregister_device(lm->idev);
for (i = 0; i < 3; i++)
if (lm->pwm[i].enabled)
led_classdev_unregister(&lm->pwm[i].cdev);
kfree(lm);
} }
/* /*
...@@ -827,7 +803,6 @@ static struct i2c_driver lm8323_i2c_driver = { ...@@ -827,7 +803,6 @@ static struct i2c_driver lm8323_i2c_driver = {
.dev_groups = lm8323_groups, .dev_groups = lm8323_groups,
}, },
.probe = lm8323_probe, .probe = lm8323_probe,
.remove = lm8323_remove,
.id_table = lm8323_id, .id_table = lm8323_id,
}; };
MODULE_DEVICE_TABLE(i2c, lm8323_id); MODULE_DEVICE_TABLE(i2c, lm8323_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment