* [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
* [PATCH 2/8] Input: amikbd - convert to use devm_* api
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api Yangtao Li
@ 2023-07-14 8:06 ` Yangtao Li
2023-07-24 5:33 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 3/8] Input: mcs-touchkey " Yangtao Li
` (6 subsequent siblings)
7 siblings, 1 reply; 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/amikbd.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index a20a4e186639..4cbac79f5a4b 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -193,10 +193,11 @@ static irqreturn_t amikbd_interrupt(int irq, void *data)
static int __init amikbd_probe(struct platform_device *pdev)
{
+ struct device *device = &pdev->dev;
struct input_dev *dev;
int i, err;
- dev = input_allocate_device();
+ dev = devm_input_allocate_device(device);
if (!dev) {
dev_err(&pdev->dev, "Not enough memory for input device\n");
return -ENOMEM;
@@ -218,35 +219,21 @@ static int __init amikbd_probe(struct platform_device *pdev)
amikbd_init_console_keymaps();
ciaa.cra &= ~0x41; /* serial data in, turn off TA */
- err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
- dev);
+ err = devm_request_irq(device, IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
+ dev);
if (err)
- goto fail2;
+ return err;
err = input_register_device(dev);
if (err)
- goto fail3;
+ return err;
platform_set_drvdata(pdev, dev);
return 0;
-
- fail3: free_irq(IRQ_AMIGA_CIAA_SP, dev);
- fail2: input_free_device(dev);
- return err;
-}
-
-static int __exit amikbd_remove(struct platform_device *pdev)
-{
- struct input_dev *dev = platform_get_drvdata(pdev);
-
- free_irq(IRQ_AMIGA_CIAA_SP, dev);
- input_unregister_device(dev);
- return 0;
}
static struct platform_driver amikbd_driver = {
- .remove = __exit_p(amikbd_remove),
.driver = {
.name = "amiga-keyboard",
},
--
2.39.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 3/8] Input: mcs-touchkey - convert to use devm_* api
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-14 8:06 ` Yangtao Li
2023-07-24 5:34 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 4/8] Input: tca6416-keypad " Yangtao Li
` (5 subsequent siblings)
7 siblings, 1 reply; 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/mcs_touchkey.c | 51 +++++++++++----------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/drivers/input/keyboard/mcs_touchkey.c b/drivers/input/keyboard/mcs_touchkey.c
index de312d8eb974..a0d2e3b1bdc9 100644
--- a/drivers/input/keyboard/mcs_touchkey.c
+++ b/drivers/input/keyboard/mcs_touchkey.c
@@ -92,10 +92,18 @@ static irqreturn_t mcs_touchkey_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
+static void mcs_touchkey_poweroff(void *data)
+{
+ struct mcs_touchkey_data *touchkey = data;
+
+ touchkey->poweron(false);
+}
+
static int mcs_touchkey_probe(struct i2c_client *client)
{
const struct i2c_device_id *id = i2c_client_get_device_id(client);
const struct mcs_platform_data *pdata;
+ struct device *dev = &client->dev;
struct mcs_touchkey_data *data;
struct input_dev *input_dev;
unsigned int fw_reg;
@@ -109,13 +117,12 @@ static int mcs_touchkey_probe(struct i2c_client *client)
return -EINVAL;
}
- data = kzalloc(struct_size(data, keycodes, pdata->key_maxval + 1),
+ data = devm_kzalloc(dev, struct_size(data, keycodes, pdata->key_maxval + 1),
GFP_KERNEL);
- input_dev = input_allocate_device();
+ input_dev = devm_input_allocate_device(dev);
if (!data || !input_dev) {
dev_err(&client->dev, "Failed to allocate memory\n");
- error = -ENOMEM;
- goto err_free_mem;
+ return -ENOMEM;
}
data->client = client;
@@ -136,9 +143,8 @@ static int mcs_touchkey_probe(struct i2c_client *client)
fw_ver = i2c_smbus_read_byte_data(client, fw_reg);
if (fw_ver < 0) {
- error = fw_ver;
dev_err(&client->dev, "i2c read error[%d]\n", error);
- goto err_free_mem;
+ return fw_ver;
}
dev_info(&client->dev, "Firmware version: %d\n", fw_ver);
@@ -169,40 +175,26 @@ static int mcs_touchkey_probe(struct i2c_client *client)
if (pdata->poweron) {
data->poweron = pdata->poweron;
data->poweron(true);
+
+ error = devm_add_action_or_reset(dev, mcs_touchkey_poweroff, data);
+ if (error)
+ return error;
}
- error = request_threaded_irq(client->irq, NULL, mcs_touchkey_interrupt,
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
- client->dev.driver->name, data);
+ error = devm_request_threaded_irq(dev, client->irq, NULL, mcs_touchkey_interrupt,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ client->dev.driver->name, data);
if (error) {
dev_err(&client->dev, "Failed to register interrupt\n");
- goto err_free_mem;
+ return error;
}
error = input_register_device(input_dev);
if (error)
- goto err_free_irq;
+ return error;
i2c_set_clientdata(client, data);
return 0;
-
-err_free_irq:
- free_irq(client->irq, data);
-err_free_mem:
- input_free_device(input_dev);
- kfree(data);
- return error;
-}
-
-static void mcs_touchkey_remove(struct i2c_client *client)
-{
- struct mcs_touchkey_data *data = i2c_get_clientdata(client);
-
- free_irq(client->irq, data);
- if (data->poweron)
- data->poweron(false);
- input_unregister_device(data->input_dev);
- kfree(data);
}
static void mcs_touchkey_shutdown(struct i2c_client *client)
@@ -259,7 +251,6 @@ static struct i2c_driver mcs_touchkey_driver = {
.pm = pm_sleep_ptr(&mcs_touchkey_pm_ops),
},
.probe = mcs_touchkey_probe,
- .remove = mcs_touchkey_remove,
.shutdown = mcs_touchkey_shutdown,
.id_table = mcs_touchkey_id,
};
--
2.39.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 4/8] Input: tca6416-keypad - convert to use devm_* api
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-14 8:06 ` [PATCH 3/8] Input: mcs-touchkey " Yangtao Li
@ 2023-07-14 8:06 ` Yangtao Li
2023-07-24 5:38 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 5/8] Input: qt1070 " Yangtao Li
` (4 subsequent siblings)
7 siblings, 1 reply; 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/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
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 5/8] Input: qt1070 - convert to use devm_* api
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api Yangtao Li
` (2 preceding siblings ...)
2023-07-14 8:06 ` [PATCH 4/8] Input: tca6416-keypad " Yangtao Li
@ 2023-07-14 8:06 ` Yangtao Li
2023-07-24 5:35 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 6/8] Input: sh-keysc " Yangtao Li
` (3 subsequent siblings)
7 siblings, 1 reply; 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/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
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6/8] Input: sh-keysc - convert to use devm_* api
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api Yangtao Li
` (3 preceding siblings ...)
2023-07-14 8:06 ` [PATCH 5/8] Input: qt1070 " Yangtao Li
@ 2023-07-14 8:06 ` Yangtao Li
2023-07-24 5:39 ` Dmitry Torokhov
2023-07-14 8:06 ` [PATCH 7/8] Input: qt2160 " Yangtao Li
` (2 subsequent siblings)
7 siblings, 1 reply; 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/sh_keysc.c | 50 +++++++++----------------------
1 file changed, 14 insertions(+), 36 deletions(-)
diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c
index 2c00320f739f..388fb87f9e56 100644
--- a/drivers/input/keyboard/sh_keysc.c
+++ b/drivers/input/keyboard/sh_keysc.c
@@ -160,6 +160,7 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
static int sh_keysc_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
struct sh_keysc_priv *priv;
struct sh_keysc_info *pdata;
struct resource *res;
@@ -169,44 +170,39 @@ static int sh_keysc_probe(struct platform_device *pdev)
if (!dev_get_platdata(&pdev->dev)) {
dev_err(&pdev->dev, "no platform data defined\n");
- error = -EINVAL;
- goto err0;
+ return -EINVAL;
}
- error = -ENXIO;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "failed to get I/O memory\n");
- goto err0;
+ return -ENXIO;
}
irq = platform_get_irq(pdev, 0);
if (irq < 0)
- goto err0;
+ return irq;
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (priv == NULL) {
dev_err(&pdev->dev, "failed to allocate driver data\n");
- error = -ENOMEM;
- goto err0;
+ return -ENOMEM;
}
platform_set_drvdata(pdev, priv);
memcpy(&priv->pdata, dev_get_platdata(&pdev->dev), sizeof(priv->pdata));
pdata = &priv->pdata;
- priv->iomem_base = ioremap(res->start, resource_size(res));
+ priv->iomem_base = devm_ioremap(dev, res->start, resource_size(res));
if (priv->iomem_base == NULL) {
dev_err(&pdev->dev, "failed to remap I/O memory\n");
- error = -ENXIO;
- goto err1;
+ return -ENXIO;
}
- priv->input = input_allocate_device();
+ priv->input = devm_input_allocate_device(dev);
if (!priv->input) {
dev_err(&pdev->dev, "failed to allocate input device\n");
- error = -ENOMEM;
- goto err2;
+ return -ENOMEM;
}
input = priv->input;
@@ -225,11 +221,11 @@ static int sh_keysc_probe(struct platform_device *pdev)
input->keycodesize = sizeof(pdata->keycodes[0]);
input->keycodemax = ARRAY_SIZE(pdata->keycodes);
- error = request_threaded_irq(irq, NULL, sh_keysc_isr, IRQF_ONESHOT,
- dev_name(&pdev->dev), pdev);
+ error = devm_request_threaded_irq(dev, irq, NULL, sh_keysc_isr, IRQF_ONESHOT,
+ dev_name(&pdev->dev), pdev);
if (error) {
dev_err(&pdev->dev, "failed to request IRQ\n");
- goto err3;
+ return error;
}
for (i = 0; i < SH_KEYSC_MAXKEYS; i++)
@@ -239,7 +235,7 @@ static int sh_keysc_probe(struct platform_device *pdev)
error = input_register_device(input);
if (error) {
dev_err(&pdev->dev, "failed to register input device\n");
- goto err4;
+ return error;
}
pm_runtime_enable(&pdev->dev);
@@ -252,17 +248,6 @@ static int sh_keysc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1);
return 0;
-
- err4:
- free_irq(irq, pdev);
- err3:
- input_free_device(input);
- err2:
- iounmap(priv->iomem_base);
- err1:
- kfree(priv);
- err0:
- return error;
}
static int sh_keysc_remove(struct platform_device *pdev)
@@ -270,16 +255,9 @@ static int sh_keysc_remove(struct platform_device *pdev)
struct sh_keysc_priv *priv = platform_get_drvdata(pdev);
sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);
-
- input_unregister_device(priv->input);
- free_irq(platform_get_irq(pdev, 0), pdev);
- iounmap(priv->iomem_base);
-
pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);
- kfree(priv);
-
return 0;
}
--
2.39.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 7/8] Input: qt2160 - convert to use devm_* api
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api Yangtao Li
` (4 preceding siblings ...)
2023-07-14 8:06 ` [PATCH 6/8] Input: sh-keysc " Yangtao Li
@ 2023-07-14 8:06 ` 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:32 ` [PATCH 1/8] Input: lm8333 " Dmitry Torokhov
7 siblings, 1 reply; 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/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
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 8/8] Input: lm8323 - convert to use devm_* api
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api Yangtao Li
` (5 preceding siblings ...)
2023-07-14 8:06 ` [PATCH 7/8] Input: qt2160 " Yangtao Li
@ 2023-07-14 8:06 ` Yangtao Li
2023-07-24 5:37 ` Dmitry Torokhov
2023-07-24 5:32 ` [PATCH 1/8] Input: lm8333 " Dmitry Torokhov
7 siblings, 1 reply; 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/lm8323.c | 41 +++++++++++----------------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index 3964f6e0f6af..d6aa4daad3ef 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -618,6 +618,7 @@ static DEVICE_ATTR(disable_kp, 0644, lm8323_show_disable, lm8323_set_disable);
static int lm8323_probe(struct i2c_client *client)
{
struct lm8323_platform_data *pdata = dev_get_platdata(&client->dev);
+ struct device *dev = &client->dev;
struct input_dev *idev;
struct lm8323_chip *lm;
int pwm;
@@ -642,12 +643,10 @@ static int lm8323_probe(struct i2c_client *client)
return -EINVAL;
}
- lm = kzalloc(sizeof *lm, GFP_KERNEL);
- idev = input_allocate_device();
- if (!lm || !idev) {
- err = -ENOMEM;
- goto fail1;
- }
+ lm = devm_kzalloc(dev, sizeof(*lm), GFP_KERNEL);
+ idev = devm_input_allocate_device(dev);
+ if (!lm || !idev)
+ return -ENOMEM;
lm->client = client;
lm->idev = idev;
@@ -684,21 +683,20 @@ static int lm8323_probe(struct i2c_client *client)
/* If a true probe check the device */
if (lm8323_read_id(lm, data) != 0) {
dev_err(&client->dev, "device not found\n");
- err = -ENODEV;
- goto fail1;
+ return -ENODEV;
}
for (pwm = 0; pwm < LM8323_NUM_PWMS; pwm++) {
err = init_pwm(lm, pwm + 1, &client->dev,
pdata->pwm_names[pwm]);
if (err < 0)
- goto fail2;
+ goto fail1;
}
lm->kp_enabled = true;
err = device_create_file(&client->dev, &dev_attr_disable_kp);
if (err < 0)
- goto fail2;
+ goto fail1;
idev->name = pdata->name ? : "LM8323 keypad";
snprintf(lm->phys, sizeof(lm->phys),
@@ -719,14 +717,14 @@ static int lm8323_probe(struct i2c_client *client)
err = input_register_device(idev);
if (err) {
dev_dbg(&client->dev, "error registering input device\n");
- goto fail3;
+ goto fail2;
}
- err = request_threaded_irq(client->irq, NULL, lm8323_irq,
- IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm);
+ err = devm_request_threaded_irq(dev, client->irq, NULL, lm8323_irq,
+ IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm);
if (err) {
dev_err(&client->dev, "could not get IRQ %d\n", client->irq);
- goto fail4;
+ goto fail2;
}
i2c_set_clientdata(client, lm);
@@ -736,18 +734,12 @@ static int lm8323_probe(struct i2c_client *client)
return 0;
-fail4:
- input_unregister_device(idev);
- idev = NULL;
-fail3:
- device_remove_file(&client->dev, &dev_attr_disable_kp);
fail2:
+ device_remove_file(&client->dev, &dev_attr_disable_kp);
+fail1:
while (--pwm >= 0)
if (lm->pwm[pwm].enabled)
led_classdev_unregister(&lm->pwm[pwm].cdev);
-fail1:
- input_free_device(idev);
- kfree(lm);
return err;
}
@@ -757,17 +749,12 @@ static void lm8323_remove(struct i2c_client *client)
int i;
disable_irq_wake(client->irq);
- free_irq(client->irq, lm);
-
- input_unregister_device(lm->idev);
device_remove_file(&lm->client->dev, &dev_attr_disable_kp);
for (i = 0; i < 3; i++)
if (lm->pwm[i].enabled)
led_classdev_unregister(&lm->pwm[i].cdev);
-
- kfree(lm);
}
/*
--
2.39.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 7/8] Input: qt2160 - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 7/8] Input: qt2160 " Yangtao Li
@ 2023-07-24 5:19 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:19 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
Hi Yangtao,
On Fri, Jul 14, 2023 at 04:06:10PM +0800, Yangtao Li wrote:
> 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;
You create a temporary, but half of the code does not use it. Please if
you introduce a temporary make sure everything is using it.
> 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) {
This double check was a cheat when resources did not free automatically,
it makes no sense to carry with devm.
> 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);
LEDs can also be registered with devm.
> -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);
It is not great that we are left with non-empty qt2160_remove(). The
driver should be converted away from using work item, and then entirety
of qt2160_remove() can be deleted.
I posted a series that cleans up the driver and incorporates an updated
version of your patch.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/8] Input: lm8333 - convert to use devm_* api
2023-07-14 8:06 [PATCH 1/8] Input: lm8333 - convert to use devm_* api Yangtao Li
` (6 preceding siblings ...)
2023-07-14 8:06 ` [PATCH 8/8] Input: lm8323 " Yangtao Li
@ 2023-07-24 5:32 ` Dmitry Torokhov
7 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:32 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
Hi Yangtao,
On Fri, Jul 14, 2023 at 04:06:04PM +0800, Yangtao Li wrote:
> 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;
This temporary is used only in few places, while the rest are still
using &client->dev. I removed it, made a couple more changes and
applied, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/8] Input: amikbd - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 2/8] Input: amikbd " Yangtao Li
@ 2023-07-24 5:33 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:33 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Fri, Jul 14, 2023 at 04:06:05PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.
Applied with minor changes, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/8] Input: mcs-touchkey - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 3/8] Input: mcs-touchkey " Yangtao Li
@ 2023-07-24 5:34 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:34 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Fri, Jul 14, 2023 at 04:06:06PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.
Applied with minor edits, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 5/8] Input: qt1070 - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 5/8] Input: qt1070 " Yangtao Li
@ 2023-07-24 5:35 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:35 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Fri, Jul 14, 2023 at 04:06:08PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.
Applied with minor edits, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 8/8] Input: lm8323 - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 8/8] Input: lm8323 " Yangtao Li
@ 2023-07-24 5:37 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:37 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Fri, Jul 14, 2023 at 04:06:11PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.
LEDs can be managed with devm, as well as we now have better way of
managing custom driver attribute; I posted a series of 2 patches
addressing this.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/8] Input: tca6416-keypad - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 4/8] Input: tca6416-keypad " Yangtao Li
@ 2023-07-24 5:38 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:38 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Fri, Jul 14, 2023 at 04:06:07PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.
The driver needs bigger facelift; I posted a series addressing this
that incorporates your patch.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 6/8] Input: sh-keysc - convert to use devm_* api
2023-07-14 8:06 ` [PATCH 6/8] Input: sh-keysc " Yangtao Li
@ 2023-07-24 5:39 ` Dmitry Torokhov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2023-07-24 5:39 UTC (permalink / raw)
To: Yangtao Li; +Cc: linux-input, linux-kernel
On Fri, Jul 14, 2023 at 04:06:09PM +0800, Yangtao Li wrote:
> Use devm_* api to simplify code, this makes it unnecessary to explicitly
> release resources.
I'd like to see a more complete conversion that results in
sh_keysc_remove() being completely removed.
Thanks.
--
Dmitry
^ permalink raw reply [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).