Input: lm8333 - convert to use devm_* api
Subsystems (2)
PATCH 1/8 Input: lm8333 - convert to use devm_* api
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/lm8333.c | 40 +++++++++------------------------ 1 file changed, 11 insertions(+), 29 deletions(-)
drivers/input/keyboard/lm8333.c +11 -29
@@ -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);
Signature · 1 line
2.39.0
PATCH 2/8 Input: amikbd - convert to use devm_* api
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/amikbd.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
drivers/input/keyboard/amikbd.c +6 -19
@@ -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" , },
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 2/8] Input: amikbd - convert to use devm_* api
Quoted 2 lines · Yangtao Li
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
Applied with minor changes, thank you.
Signature · 1 line
Dmitry
PATCH 3/8 Input: mcs-touchkey - convert to use devm_* api
In reply to Yangtao LiUse devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/mcs_touchkey.c | 51 +++++++++++---------------- 1 file changed, 21 insertions(+), 30 deletions(-)
drivers/input/keyboard/mcs_touchkey.c +21 -30
@@ -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, };
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 3/8] Input: mcs-touchkey - convert to use devm_* api
Quoted 2 lines · Yangtao Li
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
Applied with minor edits, thank you.
Signature · 1 line
Dmitry
PATCH 4/8 Input: tca6416-keypad - convert to use devm_* api
In reply to Yangtao LiUse devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/tca6416-keypad.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
drivers/input/keyboard/tca6416-keypad.c +9 -16
@@ -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)
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 4/8] Input: tca6416-keypad - convert to use devm_* api
Quoted 2 lines · Yangtao Li
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.
Signature · 1 line
Dmitry
PATCH 5/8 Input: qt1070 - convert to use devm_* api
In reply to Yangtao LiUse devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/qt1070.c | 37 ++++++++------------------------- 1 file changed, 9 insertions(+), 28 deletions(-)
drivers/input/keyboard/qt1070.c +9 -28
@@ -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);
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 5/8] Input: qt1070 - convert to use devm_* api
Quoted 2 lines · Yangtao Li
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
Applied with minor edits, thank you.
Signature · 1 line
Dmitry
PATCH 6/8 Input: sh-keysc - convert to use devm_* api
In reply to Yangtao LiUse devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/sh_keysc.c | 50 +++++++++---------------------- 1 file changed, 14 insertions(+), 36 deletions(-)
drivers/input/keyboard/sh_keysc.c +14 -36
@@ -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 ; }
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 6/8] Input: sh-keysc - convert to use devm_* api
Quoted 2 lines · Yangtao Li
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.
Signature · 1 line
Dmitry
PATCH 7/8 Input: qt2160 - convert to use devm_* api
In reply to Yangtao LiUse devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/qt2160.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
drivers/input/keyboard/qt2160.c +11 -19
@@ -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[] = {
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 7/8] Input: qt2160 - convert to use devm_* api
Hi Yangtao,
Quoted 13 lines · Yangtao Li
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
Signed-off-by Yangtao Li <[email protected]>--- drivers/input/keyboard/qt2160.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)drivers/input/keyboard/qt2160.c +0
-0
drivers/input/keyboard/qt2160.c static bool qt2160_identify(struct i2c_client *client) · line 343
Quoted 4 lines
drivers/input/keyboard/qt2160.c +1
-0@@ -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.
drivers/input/keyboard/qt2160.c static int qt2160_probe(struct i2c_client *client) · line 364
Quoted 12 lines
drivers/input/keyboard/qt2160.c +2
-2struct 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.
Quoted 37 lines
drivers/input/keyboard/qt2160.c +6
-7dev_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);
drivers/input/keyboard/qt2160.c static int qt2160_probe(struct i2c_client *client) · line 424
Quoted 3 lines
drivers/input/keyboard/qt2160.c +0
-0@@ -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.
Quoted 12 lines
drivers/input/keyboard/qt2160.c +0
-6-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);
drivers/input/keyboard/qt2160.c static int qt2160_probe(struct i2c_client *client) · line 439
Quoted 10 lines
drivers/input/keyboard/qt2160.c +2
-1+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.
Signature · 1 line
Dmitry
PATCH 8/8 Input: lm8323 - convert to use devm_* api
In reply to Yangtao LiUse devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
--- drivers/input/keyboard/lm8323.c | 41 +++++++++++---------------------- 1 file changed, 14 insertions(+), 27 deletions(-)
drivers/input/keyboard/lm8323.c +14 -27
@@ -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); }/*
Signature · 1 line
2.39.0
Dmitry Torokhov
maintainerRe: [PATCH 8/8] Input: lm8323 - convert to use devm_* api
Quoted 2 lines · Yangtao Li
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.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerHi Yangtao,
Quoted 13 lines · Yangtao Li
Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources.
Signed-off-by Yangtao Li <[email protected]>--- drivers/input/keyboard/lm8333.c | 40 +++++++++------------------------ 1 file changed, 11 insertions(+), 29 deletions(-)drivers/input/keyboard/lm8333.c +0
-0
drivers/input/keyboard/lm8333.c static int lm8333_probe(struct i2c_client *client) · line 132
Quoted 4 lines
drivers/input/keyboard/lm8333.c +1
-0@@ -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.
Signature · 1 line
Dmitry