Input: arizona-haptic - convert to use managed input devices
Subsystems (2)
Dmitry Torokhov
maintainerPATCH 1/1 Input: arizona-haptic - convert to use managed input devices
Using managed input device (via devm_input_allocate_device) simplifies error handling and driver removal paths and also silences CID# 712569.
--- drivers/input/misc/arizona-haptics.c | 52 ++++++++++++------------------------ 1 file changed, 17 insertions(+), 35 deletions(-)
drivers/input/misc/arizona-haptics.c +17 -35
@@ -152,7 +152,7 @@ static int arizona_haptics_probe(struct platform_device *pdev) {struct arizona *arizona =dev_get_drvdata (pdev->dev.parent);struct arizona_haptics *haptics; -int ret; +int error; haptics =devm_kzalloc (&pdev->dev,sizeof (*haptics),GFP_KERNEL );if (!haptics)
@@ -160,18 +160,18 @@ static int arizona_haptics_probe(struct platform_device *pdev) haptics->arizona = arizona; - ret =regmap_update_bits (arizona->regmap,ARIZONA_HAPTICS_CONTROL_1 , -ARIZONA_HAP_ACT , arizona->pdata.hap_act); -if (ret !=0 ) { + error =regmap_update_bits (arizona->regmap,ARIZONA_HAPTICS_CONTROL_1 , +ARIZONA_HAP_ACT , arizona->pdata.hap_act); +if (error) {dev_err (arizona->dev,"Failed to set haptics actuator: %d\n" , - ret); -return ret; + error); +return error; }INIT_WORK (&haptics->work, arizona_haptics_work); - haptics->input_dev =input_allocate_device (); -if (haptics->input_dev ==NULL ) { + haptics->input_dev =devm_input_allocate_device (&pdev->dev); +if (!haptics->input_dev) {dev_err (arizona->dev,"Failed to allocate input device\n" );return -ENOMEM ; }
@@ -183,46 +183,28 @@ static int arizona_haptics_probe(struct platform_device *pdev) haptics->input_dev->close = arizona_haptics_close;__set_bit (FF_RUMBLE , haptics->input_dev->ffbit); - ret =input_ff_create_memless (haptics->input_dev,NULL , - arizona_haptics_play); -if (ret <0 ) { + error =input_ff_create_memless (haptics->input_dev,NULL , + arizona_haptics_play); +if (error) {dev_err (arizona->dev,"input_ff_create_memless() failed: %d\n" , - ret); - goto err_ialloc; + error); +return error; } - ret =input_register_device (haptics->input_dev); -if (ret <0 ) { + error =input_register_device (haptics->input_dev); +if (error) {dev_err (arizona->dev,"couldn't register input device: %d\n" , - ret); - goto err_iff; + error); +return error; }platform_set_drvdata (pdev, haptics);return 0 ; - -err_iff: -if (haptics->input_dev) -input_ff_destroy (haptics->input_dev); -err_ialloc: -input_free_device (haptics->input_dev); - -return ret; -} - -static int arizona_haptics_remove (struct platform_device *pdev) -{ -struct arizona_haptics *haptics =platform_get_drvdata (pdev); - -input_unregister_device (haptics->input_dev); - -return 0 ; }static struct platform_driver arizona_haptics_driver = { .probe = arizona_haptics_probe, - .remove = arizona_haptics_remove, .driver = { .name ="arizona-haptics" , },
Signature · 5 lines
2.4.3.573.g4eafbef -- Dmitry
Hi,
It seems to me that swapping error for ret buries the functional changes in the patch...
would it be better to split them into a second cleanup patch?
Quoted 50 lines · Dmitry Torokhov
Using managed input device (via
devm_input_allocate_device) simplifies error handling and driver removal paths and also silences CID# 712569.Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/input/misc/arizona-haptics.c | 52++++++++++++------------------------ 1 file changed, 17 insertions(+), 35 deletions(-)
(quoted diff) +0
-0
b/drivers/input/misc/arizona-haptics.cindex 4dbbed7..54ebef2 100644drivers/input/misc/arizona-haptics.c +8
-8@@ -152,7 +152,7 @@ static int arizona_haptics_probe(struct platform_device *pdev) {struct arizona *arizona =dev_get_drvdata (pdev->dev.parent);struct arizona_haptics *haptics; -int ret; +int error; haptics =devm_kzalloc (&pdev->dev,sizeof (*haptics),GFP_KERNEL );if (!haptics)@@ -160,18 +160,18 @@ static int arizona_haptics_probe(struct platform_device *pdev) haptics->arizona = arizona; - ret =regmap_update_bits (arizona->regmap,ARIZONA_HAPTICS_CONTROL_1 , -ARIZONA_HAP_ACT , arizona->pdata.hap_act); -if (ret !=0 ) { + error =regmap_update_bits (arizona->regmap,ARIZONA_HAPTICS_CONTROL_1 , +ARIZONA_HAP_ACT , arizona->pdata.hap_act); +if (error) {dev_err (arizona->dev,"Failed to set haptics actuator: %d\n" , - ret); -return ret; + error); +return error; }INIT_WORK (&haptics->work, arizona_haptics_work); - haptics->input_dev =input_allocate_device (); -if (haptics->input_dev ==NULL ) { + haptics->input_dev =devm_input_allocate_device (&pdev->dev); +if (!haptics->input_dev) {dev_err (arizona->dev,"Failed to allocate input device\n" );return -ENOMEM ;drivers/input/misc/arizona-haptics.c +0
-0}
drivers/input/misc/arizona-haptics.c static int arizona_haptics_probe(struct · line 188
Quoted 9 lines
drivers/input/misc/arizona-haptics.c +3
-3@@ -183,46 +183,28 @@ static int arizona_haptics_probe(struct platform_device *pdev) haptics->input_dev->close = arizona_haptics_close;__set_bit (FF_RUMBLE , haptics->input_dev->ffbit); - ret =input_ff_create_memless (haptics->input_dev,NULL , - arizona_haptics_play); -if (ret <0 ) { + error =input_ff_create_memless (haptics->input_dev,NULL , + arizona_haptics_play); +if (error) {
This looks OK. No change in behavior. Underlying functions return 0 or a negative number.
drivers/input/misc/arizona-haptics.c static int arizona_haptics_probe(struct platform_device *pdev) · line 195
Quoted 11 lines
drivers/input/misc/arizona-haptics.c +4
-4dev_err (arizona->dev,"input_ff_create_memless() failed: %d\n" , - ret); - goto err_ialloc; + error); +return error; } - ret = (haptics->input_dev); -if (ret <0 ) { + error =input_register_device (haptics->input_dev); +if (error) {
Same here.
...
Signature · 1 line
~Joshua Clayton
Dmitry Torokhov
maintainerQuoted 4 lines · Joshua Clayton
Hi,
It seems to me that swapping error for ret buries the functional changes in the patch...
would it be better to split them into a second cleanup patch?
Fair enough, although I am not sure if I ever get to the renaming again ;)
Thanks.
Signature · 14 lines
Dmitry Input: arizona-haptic - convert to use managed input devices From: Dmitry Torokhov <[email protected]> Using managed input device (via devm_input_allocate_device) simplifies error handling and driver removal paths and also silences CID# 712569. Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/input/misc/arizona-haptics.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/input/misc/arizona-haptics.c +4 -22
@@ -170,8 +170,8 @@ static int arizona_haptics_probe(struct platform_device *pdev)INIT_WORK (&haptics->work, arizona_haptics_work); - haptics->input_dev =input_allocate_device (); -if (haptics->input_dev ==NULL ) { + haptics->input_dev =devm_input_allocate_device (&pdev->dev); +if (!haptics->input_dev) {dev_err (arizona->dev,"Failed to allocate input device\n" );return -ENOMEM ; }
@@ -188,41 +188,23 @@ static int arizona_haptics_probe(struct platform_device *pdev)if (ret <0 ) {dev_err (arizona->dev,"input_ff_create_memless() failed: %d\n" , ret); - goto err_ialloc; +return ret; } ret =input_register_device (haptics->input_dev);if (ret <0 ) {dev_err (arizona->dev,"couldn't register input device: %d\n" , ret); - goto err_iff; +return ret; }platform_set_drvdata (pdev, haptics);return 0 ; - -err_iff: -if (haptics->input_dev) -input_ff_destroy (haptics->input_dev); -err_ialloc: -input_free_device (haptics->input_dev); - -return ret; -} - -static int arizona_haptics_remove (struct platform_device *pdev) -{ -struct arizona_haptics *haptics =platform_get_drvdata (pdev); - -input_unregister_device (haptics->input_dev); - -return 0 ; }static struct platform_driver arizona_haptics_driver = { .probe = arizona_haptics_probe, - .remove = arizona_haptics_remove, .driver = { .name ="arizona-haptics" , },
Dmitry Torokhov
maintainerQuoted 8 lines · Dmitry Torokhov
Quoted 4 lines · Joshua Clayton
Hi,
It seems to me that swapping error for ret buries the functional changes in the patch...
would it be better to split them into a second cleanup patch?Fair enough, although I am not sure if I ever get to the renaming again ;)
Joshua, does the below look OK to you?
Thanks!
Quoted 78 lines
Thanks.
Signature · 14 lines
Dmitry Input: arizona-haptic - convert to use managed input devices From: Dmitry Torokhov <[email protected]> Using managed input device (via devm_input_allocate_device) simplifies error handling and driver removal paths and also silences CID# 712569. Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/input/misc/arizona-haptics.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/input/misc/arizona-haptics.c +4
-22@@ -170,8 +170,8 @@ static int arizona_haptics_probe(struct platform_device *pdev)INIT_WORK (&haptics->work, arizona_haptics_work); - haptics->input_dev =input_allocate_device (); -if (haptics->input_dev ==NULL ) { + haptics->input_dev =devm_input_allocate_device (&pdev->dev); +if (!haptics->input_dev) {dev_err (arizona->dev,"Failed to allocate input device\n" );return -ENOMEM ; }@@ -188,41 +188,23 @@ static int arizona_haptics_probe(struct platform_device *pdev)if (ret <0 ) {dev_err (arizona->dev,"input_ff_create_memless() failed: %d\n" , ret); - goto err_ialloc; +return ret; } ret =input_register_device (haptics->input_dev);if (ret <0 ) {dev_err (arizona->dev,"couldn't register input device: %d\n" , ret); - goto err_iff; +return ret; }platform_set_drvdata (pdev, haptics);return 0 ; - -err_iff: -if (haptics->input_dev) -input_ff_destroy (haptics->input_dev); -err_ialloc: -input_free_device (haptics->input_dev); - -return ret; -} - -static int arizona_haptics_remove (struct platform_device *pdev) -{ -struct arizona_haptics *haptics =platform_get_drvdata (pdev); - -input_unregister_device (haptics->input_dev); - -return 0 ; }static struct platform_driver arizona_haptics_driver = { .probe = arizona_haptics_probe, - .remove = arizona_haptics_remove, .driver = { .name ="arizona-haptics" , },
Signature · 1 line
Dmitry
Quoted 86 lines · Dmitry Torokhov
Quoted 8 lines · Dmitry Torokhov
Quoted 4 lines · Joshua Clayton
Hi,
It seems to me that swapping error for ret buries the functional changes in the patch...
would it be better to split them into a second cleanup patch?Fair enough, although I am not sure if I ever get to the renaming again
Joshua, does the below look OK to you?
Thanks!
Quoted 72 lines
Thanks.
Signature · 14 lines
Dmitry Input: arizona-haptic - convert to use managed input devices From: Dmitry Torokhov <[email protected]> Using managed input device (via devm_input_allocate_device) simplifies error handling and driver removal paths and also silences CID# 712569. Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/input/misc/arizona-haptics.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/input/misc/arizona-haptics.c +4
-21@@ -170,8 +170,8 @@ static int arizona_haptics_probe(struct platform_device *pdev)INIT_WORK (&haptics->work, arizona_haptics_work); - haptics->input_dev =input_allocate_device (); -if (haptics->input_dev ==NULL ) { + haptics->input_dev =devm_input_allocate_device (&pdev->dev); +if (!haptics->input_dev) {dev_err (arizona->dev,"Failed to allocate input device\n" );return -ENOMEM ; }@@ -188,41 +188,23 @@ static int arizona_haptics_probe(struct platform_device *pdev)if (ret <0 ) {dev_err (arizona->dev,"input_ff_create_memless() failed: %d\n" , ret); - goto err_ialloc; +return ret; } ret =input_register_device (haptics->input_dev);if (ret <0 ) {dev_err (arizona->dev,"couldn't register input device: %d\n" , ret); - goto err_iff; +return ret; }platform_set_drvdata (pdev, haptics);return 0 ; - -err_iff: -if (haptics->input_dev) -input_ff_destroy (haptics->input_dev); -err_ialloc: -input_free_device (haptics->input_dev); - -return ret; -} - -static int arizona_haptics_remove (struct platform_device *pdev) -{ -struct arizona_haptics *haptics =platform_get_drvdata (pdev); - -input_unregister_device (haptics->input_dev); - -return 0 ; }
Quoted 9 lines
Quoted 6 lines
drivers/input/misc/arizona-haptics.c +0
-1static struct platform_driver arizona_haptics_driver = { .probe = arizona_haptics_probe, - .remove = arizona_haptics_remove, .driver = { .name ="arizona-haptics" , },Signature · 1 line
Dmitry
devm for the win.
Yes, that looks good.
Signature · 1 line
~Joshua Clayton