mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 7/8] Input: qt2160 - convert to use devm_* api
Date: Fri, 14 Jul 2023 16:06:10 +0800	[thread overview]
Message-ID: <20230714080611.81302-7-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/qt2160.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c
index 599ea85cfd30..218ef92b8c2b 100644
--- a/drivers/input/keyboard/qt2160.c
+++ b/drivers/input/keyboard/qt2160.c
@@ -340,6 +340,7 @@ static bool qt2160_identify(struct i2c_client *client)
 
 static int qt2160_probe(struct i2c_client *client)
 {
+	struct device *dev = &client->dev;
 	struct qt2160_data *qt2160;
 	struct input_dev *input;
 	int i;
@@ -358,12 +359,11 @@ static int qt2160_probe(struct i2c_client *client)
 		return -ENODEV;
 
 	/* Chip is valid and active. Allocate structure */
-	qt2160 = kzalloc(sizeof(struct qt2160_data), GFP_KERNEL);
-	input = input_allocate_device();
+	qt2160 = devm_kzalloc(dev, sizeof(struct qt2160_data), GFP_KERNEL);
+	input = devm_input_allocate_device(dev);
 	if (!qt2160 || !input) {
 		dev_err(&client->dev, "insufficient memory\n");
-		error = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	qt2160->client = client;
@@ -389,23 +389,23 @@ static int qt2160_probe(struct i2c_client *client)
 	error = qt2160_write(client, QT2160_CMD_CALIBRATE, 1);
 	if (error) {
 		dev_err(&client->dev, "failed to calibrate device\n");
-		goto err_free_mem;
+		return error;
 	}
 
 	if (client->irq) {
-		error = request_irq(client->irq, qt2160_irq,
-				    IRQF_TRIGGER_FALLING, "qt2160", qt2160);
+		error = devm_request_irq(dev, client->irq, qt2160_irq,
+					 IRQF_TRIGGER_FALLING, "qt2160", qt2160);
 		if (error) {
 			dev_err(&client->dev,
 				"failed to allocate irq %d\n", client->irq);
-			goto err_free_mem;
+			return error;
 		}
 	}
 
 	error = qt2160_register_leds(qt2160);
 	if (error) {
 		dev_err(&client->dev, "Failed to register leds\n");
-		goto err_free_irq;
+		return error;
 	}
 
 	error = input_register_device(qt2160->input);
@@ -422,29 +422,21 @@ static int qt2160_probe(struct i2c_client *client)
 
 err_unregister_leds:
 	qt2160_unregister_leds(qt2160);
-err_free_irq:
-	if (client->irq)
-		free_irq(client->irq, qt2160);
-err_free_mem:
-	input_free_device(input);
-	kfree(qt2160);
 	return error;
 }
 
 static void qt2160_remove(struct i2c_client *client)
 {
 	struct qt2160_data *qt2160 = i2c_get_clientdata(client);
+	struct device *dev = &client->dev;
 
 	qt2160_unregister_leds(qt2160);
 
 	/* Release IRQ so no queue will be scheduled */
 	if (client->irq)
-		free_irq(client->irq, qt2160);
+		devm_free_irq(dev, client->irq, qt2160);
 
 	cancel_delayed_work_sync(&qt2160->dwork);
-
-	input_unregister_device(qt2160->input);
-	kfree(qt2160);
 }
 
 static const struct i2c_device_id qt2160_idtable[] = {
-- 
2.39.0


  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 ` Yangtao Li [this message]
2023-07-24  5:19   ` [PATCH 7/8] Input: qt2160 " Dmitry Torokhov
2023-07-14  8:06 ` [PATCH 8/8] Input: lm8323 " Yangtao Li
2023-07-24  5:37   ` 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-7-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®