linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/8] Input: lm8333 - convert to use devm_* api
@ 2023-07-14  8:06 Yangtao Li
  2023-07-14  8:06 ` [PATCH 2/8] Input: amikbd " Yangtao Li
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Yangtao Li @ 2023-07-14  8:06 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Yangtao Li, linux-input, linux-kernel

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/lm8333.c | 40 +++++++++------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/drivers/input/keyboard/lm8333.c b/drivers/input/keyboard/lm8333.c
index c9f05764e36d..41d088933e01 100644
--- a/drivers/input/keyboard/lm8333.c
+++ b/drivers/input/keyboard/lm8333.c
@@ -129,6 +129,7 @@ static int lm8333_probe(struct i2c_client *client)
 {
 	const struct lm8333_platform_data *pdata =
 			dev_get_platdata(&client->dev);
+	struct device *dev = &client->dev;
 	struct lm8333 *lm8333;
 	struct input_dev *input;
 	int err, active_time;
@@ -142,12 +143,10 @@ static int lm8333_probe(struct i2c_client *client)
 		return -EINVAL;
 	}
 
-	lm8333 = kzalloc(sizeof(*lm8333), GFP_KERNEL);
-	input = input_allocate_device();
-	if (!lm8333 || !input) {
-		err = -ENOMEM;
-		goto free_mem;
-	}
+	lm8333 = devm_kzalloc(dev, sizeof(*lm8333), GFP_KERNEL);
+	input = devm_input_allocate_device(dev);
+	if (!lm8333 || !input)
+		return -ENOMEM;
 
 	lm8333->client = client;
 	lm8333->input = input;
@@ -162,7 +161,7 @@ static int lm8333_probe(struct i2c_client *client)
 					 LM8333_NUM_ROWS, LM8333_NUM_COLS,
 					 lm8333->keycodes, input);
 	if (err)
-		goto free_mem;
+		return err;
 
 	if (pdata->debounce_time) {
 		err = lm8333_write8(lm8333, LM8333_DEBOUNCE,
@@ -178,34 +177,18 @@ static int lm8333_probe(struct i2c_client *client)
 			dev_warn(&client->dev, "Unable to set active time\n");
 	}
 
-	err = request_threaded_irq(client->irq, NULL, lm8333_irq_thread,
-				   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
-				   "lm8333", lm8333);
+	err = devm_request_threaded_irq(dev, client->irq, NULL, lm8333_irq_thread,
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					"lm8333", lm8333);
 	if (err)
-		goto free_mem;
+		return err;
 
 	err = input_register_device(input);
 	if (err)
-		goto free_irq;
+		return err;
 
 	i2c_set_clientdata(client, lm8333);
 	return 0;
-
- free_irq:
-	free_irq(client->irq, lm8333);
- free_mem:
-	input_free_device(input);
-	kfree(lm8333);
-	return err;
-}
-
-static void lm8333_remove(struct i2c_client *client)
-{
-	struct lm8333 *lm8333 = i2c_get_clientdata(client);
-
-	free_irq(client->irq, lm8333);
-	input_unregister_device(lm8333->input);
-	kfree(lm8333);
 }
 
 static const struct i2c_device_id lm8333_id[] = {
@@ -219,7 +202,6 @@ static struct i2c_driver lm8333_driver = {
 		.name		= "lm8333",
 	},
 	.probe		= lm8333_probe,
-	.remove		= lm8333_remove,
 	.id_table	= lm8333_id,
 };
 module_i2c_driver(lm8333_driver);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-07-24  5:39 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-14  8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api 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 ` [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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).