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 5/8] Input: qt1070 - convert to use devm_* api
Date: Fri, 14 Jul 2023 16:06:08 +0800	[thread overview]
Message-ID: <20230714080611.81302-5-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/qt1070.c | 37 ++++++++-------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)

diff --git a/drivers/input/keyboard/qt1070.c b/drivers/input/keyboard/qt1070.c
index 91aaa9fc43a4..b240779b6a93 100644
--- a/drivers/input/keyboard/qt1070.c
+++ b/drivers/input/keyboard/qt1070.c
@@ -128,6 +128,7 @@ static irqreturn_t qt1070_interrupt(int irq, void *dev_id)
 
 static int qt1070_probe(struct i2c_client *client)
 {
+	struct device *dev = &client->dev;
 	struct qt1070_data *data;
 	struct input_dev *input;
 	int i;
@@ -149,12 +150,11 @@ static int qt1070_probe(struct i2c_client *client)
 	if (!qt1070_identify(client))
 		return -ENODEV;
 
-	data = kzalloc(sizeof(struct qt1070_data), GFP_KERNEL);
-	input = input_allocate_device();
+	data = devm_kzalloc(dev, sizeof(struct qt1070_data), GFP_KERNEL);
+	input = devm_input_allocate_device(dev);
 	if (!data || !input) {
 		dev_err(&client->dev, "insufficient memory\n");
-		err = -ENOMEM;
-		goto err_free_mem;
+		return -ENOMEM;
 	}
 
 	data->client = client;
@@ -185,19 +185,19 @@ static int qt1070_probe(struct i2c_client *client)
 	qt1070_write(client, RESET, 1);
 	msleep(QT1070_RESET_TIME);
 
-	err = request_threaded_irq(client->irq, NULL, qt1070_interrupt,
-				   IRQF_TRIGGER_NONE | IRQF_ONESHOT,
-				   client->dev.driver->name, data);
+	err = devm_request_threaded_irq(dev, client->irq, NULL, qt1070_interrupt,
+					IRQF_TRIGGER_NONE | IRQF_ONESHOT,
+					client->dev.driver->name, data);
 	if (err) {
 		dev_err(&client->dev, "fail to request irq\n");
-		goto err_free_mem;
+		return err;
 	}
 
 	/* Register the input device */
 	err = input_register_device(data->input);
 	if (err) {
 		dev_err(&client->dev, "Failed to register input device\n");
-		goto err_free_irq;
+		return err;
 	}
 
 	i2c_set_clientdata(client, data);
@@ -206,24 +206,6 @@ static int qt1070_probe(struct i2c_client *client)
 	qt1070_read(client, DET_STATUS);
 
 	return 0;
-
-err_free_irq:
-	free_irq(client->irq, data);
-err_free_mem:
-	input_free_device(input);
-	kfree(data);
-	return err;
-}
-
-static void qt1070_remove(struct i2c_client *client)
-{
-	struct qt1070_data *data = i2c_get_clientdata(client);
-
-	/* Release IRQ */
-	free_irq(client->irq, data);
-
-	input_unregister_device(data->input);
-	kfree(data);
 }
 
 static int qt1070_suspend(struct device *dev)
@@ -272,7 +254,6 @@ static struct i2c_driver qt1070_driver = {
 	},
 	.id_table	= qt1070_id,
 	.probe		= qt1070_probe,
-	.remove		= qt1070_remove,
 };
 
 module_i2c_driver(qt1070_driver);
-- 
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 ` Yangtao Li [this message]
2023-07-24  5:35   ` [PATCH 5/8] Input: qt1070 " 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 ` [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-5-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®