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

diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c
index 2f745cabf4f2..8db204696191 100644
--- a/drivers/input/keyboard/tca6416-keypad.c
+++ b/drivers/input/keyboard/tca6416-keypad.c
@@ -198,6 +198,7 @@ static int tca6416_keypad_probe(struct i2c_client *client)
 {
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 	struct tca6416_keys_platform_data *pdata;
+	struct device *dev = &client->dev;
 	struct tca6416_keypad_chip *chip;
 	struct input_dev *input;
 	int error;
@@ -216,12 +217,10 @@ static int tca6416_keypad_probe(struct i2c_client *client)
 		return -EINVAL;
 	}
 
-	chip = kzalloc(struct_size(chip, buttons, pdata->nbuttons), GFP_KERNEL);
-	input = input_allocate_device();
-	if (!chip || !input) {
-		error = -ENOMEM;
-		goto fail1;
-	}
+	chip = devm_kzalloc(dev, struct_size(chip, buttons, pdata->nbuttons), GFP_KERNEL);
+	input = devm_input_allocate_device(dev);
+	if (!chip || !input)
+		return -ENOMEM;
 
 	chip->client = client;
 	chip->input = input;
@@ -263,7 +262,7 @@ static int tca6416_keypad_probe(struct i2c_client *client)
 	 */
 	error = tca6416_setup_registers(chip);
 	if (error)
-		goto fail1;
+		return error;
 
 	if (!chip->use_polling) {
 		if (pdata->irq_is_gpio)
@@ -280,7 +279,7 @@ static int tca6416_keypad_probe(struct i2c_client *client)
 			dev_dbg(&client->dev,
 				"Unable to claim irq %d; error %d\n",
 				chip->irqnum, error);
-			goto fail1;
+			return error;
 		}
 	}
 
@@ -288,7 +287,7 @@ static int tca6416_keypad_probe(struct i2c_client *client)
 	if (error) {
 		dev_dbg(&client->dev,
 			"Unable to register input device, error: %d\n", error);
-		goto fail2;
+		goto fail;
 	}
 
 	i2c_set_clientdata(client, chip);
@@ -296,14 +295,11 @@ static int tca6416_keypad_probe(struct i2c_client *client)
 
 	return 0;
 
-fail2:
+fail:
 	if (!chip->use_polling) {
 		free_irq(chip->irqnum, chip);
 		enable_irq(chip->irqnum);
 	}
-fail1:
-	input_free_device(input);
-	kfree(chip);
 	return error;
 }
 
@@ -315,9 +311,6 @@ static void tca6416_keypad_remove(struct i2c_client *client)
 		free_irq(chip->irqnum, chip);
 		enable_irq(chip->irqnum);
 	}
-
-	input_unregister_device(chip->input);
-	kfree(chip);
 }
 
 static int tca6416_keypad_suspend(struct device *dev)
-- 
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 ` Yangtao Li [this message]
2023-07-24  5:38   ` [PATCH 4/8] Input: tca6416-keypad " 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 ` [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-4-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®