From: Yangtao Li <frank.li@vivo.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Yangtao Li <frank.li@vivo.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 8/8] Input: lm8323 - convert to use devm_* api
Date: Fri, 14 Jul 2023 16:06:11 +0800 [thread overview]
Message-ID: <20230714080611.81302-8-frank.li@vivo.com> (raw)
In-Reply-To: <20230714080611.81302-1-frank.li@vivo.com>
Use devm_* api to simplify code, this makes it unnecessary to explicitly
release resources.
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
drivers/input/keyboard/lm8323.c | 41 +++++++++++----------------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index 3964f6e0f6af..d6aa4daad3ef 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -618,6 +618,7 @@ static DEVICE_ATTR(disable_kp, 0644, lm8323_show_disable, lm8323_set_disable);
static int lm8323_probe(struct i2c_client *client)
{
struct lm8323_platform_data *pdata = dev_get_platdata(&client->dev);
+ struct device *dev = &client->dev;
struct input_dev *idev;
struct lm8323_chip *lm;
int pwm;
@@ -642,12 +643,10 @@ static int lm8323_probe(struct i2c_client *client)
return -EINVAL;
}
- lm = kzalloc(sizeof *lm, GFP_KERNEL);
- idev = input_allocate_device();
- if (!lm || !idev) {
- err = -ENOMEM;
- goto fail1;
- }
+ lm = devm_kzalloc(dev, sizeof(*lm), GFP_KERNEL);
+ idev = devm_input_allocate_device(dev);
+ if (!lm || !idev)
+ return -ENOMEM;
lm->client = client;
lm->idev = idev;
@@ -684,21 +683,20 @@ static int lm8323_probe(struct i2c_client *client)
/* If a true probe check the device */
if (lm8323_read_id(lm, data) != 0) {
dev_err(&client->dev, "device not found\n");
- err = -ENODEV;
- goto fail1;
+ return -ENODEV;
}
for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) {
err = init_pwm(lm, pwm + 1, &client->dev,
pdata->pwm_names[pwm]);
if (err < 0)
- goto fail2;
+ goto fail1;
}
lm->kp_enabled = true;
err = device_create_file(&client->dev, &dev_attr_disable_kp);
if (err < 0)
- goto fail2;
+ goto fail1;
idev->name = pdata->name ? : "LM8323 keypad";
snprintf(lm->phys, sizeof(lm->phys),
@@ -719,14 +717,14 @@ static int lm8323_probe(struct i2c_client *client)
err = input_register_device(idev);
if (err) {
dev_dbg(&client->dev, "error registering input device\n");
- goto fail3;
+ goto fail2;
}
- err = request_threaded_irq(client->irq, NULL, lm8323_irq,
- IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm);
+ err = devm_request_threaded_irq(dev, client->irq, NULL, lm8323_irq,
+ IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm);
if (err) {
dev_err(&client->dev, "could not get IRQ %d\n", client->irq);
- goto fail4;
+ goto fail2;
}
i2c_set_clientdata(client, lm);
@@ -736,18 +734,12 @@ static int lm8323_probe(struct i2c_client *client)
return 0;
-fail4:
- input_unregister_device(idev);
- idev = NULL;
-fail3:
- device_remove_file(&client->dev, &dev_attr_disable_kp);
fail2:
+ device_remove_file(&client->dev, &dev_attr_disable_kp);
+fail1:
while (--pwm >= 0)
if (lm->pwm[pwm].enabled)
led_classdev_unregister(&lm->pwm[pwm].cdev);
-fail1:
- input_free_device(idev);
- kfree(lm);
return err;
}
@@ -757,17 +749,12 @@ static void lm8323_remove(struct i2c_client *client)
int i;
disable_irq_wake(client->irq);
- free_irq(client->irq, lm);
-
- input_unregister_device(lm->idev);
device_remove_file(&lm->client->dev, &dev_attr_disable_kp);
for (i = 0; i < 3; i++)
if (lm->pwm[i].enabled)
led_classdev_unregister(&lm->pwm[i].cdev);
-
- kfree(lm);
}
/*
--
2.39.0
next prev parent reply other threads:[~2023-07-14 8:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 " Yangtao Li
2023-07-14 8:06 ` [PATCH 2/8] Input: amikbd " Yangtao Li
2023-07-24 5:33 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 3/8] Input: mcs-touchkey " Yangtao Li
2023-07-24 5:34 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 4/8] Input: tca6416-keypad " Yangtao Li
2023-07-24 5:38 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 5/8] Input: qt1070 " Yangtao Li
2023-07-24 5:35 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 6/8] Input: sh-keysc " Yangtao Li
2023-07-24 5:39 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 7/8] Input: qt2160 " Yangtao Li
2023-07-24 5:19 ` Dmitry Torokhov
2023-07-14 8:06 ` Yangtao Li [this message]
2023-07-24 5:37 ` [PATCH 8/8] Input: lm8323 " Dmitry Torokhov
2023-07-24 5:32 ` [PATCH 1/8] Input: lm8333 " Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230714080611.81302-8-frank.li@vivo.com \
--to=frank.li@vivo.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®