diff mbox series

[4/8] Input: tca6416-keypad - convert to use devm_* api

Message ID 20230714080611.81302-4-frank.li@vivo.com
State New
Headers show
Series [1/8] Input: lm8333 - convert to use devm_* api | expand

Commit Message

李扬韬 July 14, 2023, 8:06 a.m. UTC
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 mbox series

Patch

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)