input: gpio_keys_polled: Convert to devm-* API
Subsystems (2)
PATCH RESEND 1/2 input: gpio_keys_polled: Convert to devm-* API
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc -> devm_kzallocgpio_request_one -> devm_gpio_request_one
--- drivers/input/keyboard/gpio_keys_polled.c | 87 ++++++++----------------------- 1 file changed, 23 insertions(+), 64 deletions(-)
drivers/input/keyboard/gpio_keys_polled.c +23 -64
@@ -108,9 +108,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structstruct device_node *node, *pp;struct gpio_keys_platform_data *pdata;struct gpio_keys_button *button; -int error; -int nbuttons; -int i; +int i, nbuttons; node = dev->of_node;if (!node)
@@ -120,12 +118,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (nbuttons ==0 )return NULL ; - pdata =kzalloc (sizeof (*pdata) + nbuttons * (sizeof *button), -GFP_KERNEL ); -if (!pdata) { - error = -ENOMEM ; - goto err_out; - } + pdata =devm_kzalloc (dev,sizeof (*pdata) + nbuttons *sizeof (*button), +GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); pdata->buttons = (struct gpio_keys_button *)(pdata +1 ); pdata->nbuttons = nbuttons;
@@ -146,12 +142,11 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct gpio =of_get_gpio_flags (pp,0 , &flags);if (gpio <0 ) { - error = gpio; -if (error != -EPROBE_DEFER ) +if (gpio != -EPROBE_DEFER )dev_err (dev,"Failed to get gpio flags, error: %d\n" , - error); - goto err_free_pdata; + gpio); +return ERR_PTR (gpio); } button = &pdata->buttons[i++];
@@ -162,8 +157,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); } button->desc =of_get_property (pp,"label" ,NULL );
@@ -178,17 +172,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct button->debounce_interval =5 ; } -if (pdata->nbuttons ==0 ) { - error = -EINVAL ; - goto err_free_pdata; - } +if (!pdata->nbuttons) +return ERR_PTR (-EINVAL );return pdata; - -err_free_pdata: -kfree (pdata); -err_out: -return ERR_PTR (error); }static struct of_device_id gpio_keys_polled_of_match[] = {
@@ -228,24 +215,21 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)if (!pdata->poll_interval) {dev_err (dev,"missing poll_interval value\n" ); - error = -EINVAL ; - goto err_free_pdata; +return -EINVAL ; } - bdev =kzalloc (sizeof (struct gpio_keys_polled_dev ) + - pdata->nbuttons *sizeof (struct gpio_keys_button_data ), -GFP_KERNEL ); + bdev =devm_kzalloc (&pdev->dev,sizeof (struct gpio_keys_polled_dev ) + + pdata->nbuttons *sizeof (struct gpio_keys_button_data ), +GFP_KERNEL );if (!bdev) {dev_err (dev,"no memory for private data\n" ); - error = -ENOMEM ; - goto err_free_pdata; +return -ENOMEM ; } poll_dev =input_allocate_polled_device ();if (!poll_dev) {dev_err (dev,"no memory for polled device\n" ); - error = -ENOMEM ; - goto err_free_bdev; +return -ENOMEM ; } poll_dev->private = bdev;
@@ -278,15 +262,15 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)if (button->wakeup) {dev_err (dev,DRV_NAME " does not support wakeup\n" ); error = -EINVAL ; - goto err_free_gpio; + goto err_out; } - error =gpio_request_one (gpio,GPIOF_IN , - button->desc ?:DRV_NAME ); + error =devm_gpio_request_one (&pdev->dev, gpio,GPIOF_IN , + button->desc ? :DRV_NAME );if (error) {dev_err (dev,"unable to claim gpio %u, err=%d\n" , gpio, error); - goto err_free_gpio; + goto err_out; } bdata->can_sleep =gpio_cansleep (gpio);
@@ -306,7 +290,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)if (error) {dev_err (dev,"unable to register polled device, err=%d\n" , error); - goto err_free_gpio; + goto err_out; }/* report initial state of the buttons */
@@ -316,45 +300,20 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)return 0 ; -err_free_gpio: -while (--i >=0 ) -gpio_free (pdata->buttons[i].gpio); - +err_out:input_free_polled_device (poll_dev); -err_free_bdev: -kfree (bdev); - -err_free_pdata: -/* If we have no platform_data, we allocated pdata dynamically. */ -if (!dev_get_platdata (&pdev->dev)) -kfree (pdata); -return error; }static int gpio_keys_polled_remove (struct platform_device *pdev) {struct gpio_keys_polled_dev *bdev =platform_get_drvdata (pdev); -const struct gpio_keys_platform_data *pdata = bdev->pdata; -int i;input_unregister_polled_device (bdev->poll_dev); -for (i =0 ; i < pdata->nbuttons; i++) -gpio_free (pdata->buttons[i].gpio); -input_free_polled_device (bdev->poll_dev); -/* -* If we had no platform_data, we allocated pdata dynamically and -* must free it here. -*/ -if (!dev_get_platdata (&pdev->dev)) -kfree (pdata); - -kfree (bdev); -return 0 ; }
Signature · 1 line
1.8.3.2
PATCH RESEND 2/2 input: gpio_keys: Convert to devm-* API
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc -> devm_kzallocgpio_request_one -> devm_gpio_request_one input_allocate_device -> devm_input_allocate_device
--- drivers/input/keyboard/gpio_keys.c | 96 +++++++++++--------------------------- 1 file changed, 28 insertions(+), 68 deletions(-)
drivers/input/keyboard/gpio_keys.c +28 -68
@@ -433,7 +433,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev,struct device *dev = &pdev->dev;irq_handler_t isr;unsigned long irqflags; -int irq, error; +int error; bdata->input = input; bdata->button = button;
@@ -441,7 +441,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,if (gpio_is_valid (button->gpio)) { - error =gpio_request_one (button->gpio,GPIOF_IN , desc); + error =devm_gpio_request_one (&pdev->dev, button->gpio, +GPIOF_IN , desc);if (error <0 ) {dev_err (dev,"Failed to request GPIO %d, error %d\n" , button->gpio, error);
@@ -457,15 +458,13 @@ static int gpio_keys_setup_key(struct platform_device *pdev, button->debounce_interval; } - irq =gpio_to_irq (button->gpio); -if (irq <0 ) { - error = irq; + bdata->irq =gpio_to_irq (button->gpio); +if (bdata->irq <0 ) {dev_err (dev,"Unable to get irq number for GPIO %d, error %d\n" , - button->gpio, error); - goto fail; + button->gpio, bdata->irq); +return bdata->irq; } - bdata->irq = irq;INIT_WORK (&bdata->work, gpio_keys_gpio_work_func); setup_timer(&bdata->timer,
@@ -507,16 +506,10 @@ static int gpio_keys_setup_key(struct platform_device *pdev,if (error <0 ) {dev_err (dev,"Unable to claim irq %d; error %d\n" , bdata->irq, error); - goto fail; +return error; }return 0 ; - -fail: -if (gpio_is_valid (button->gpio)) -gpio_free (button->gpio); - -return error; }static void gpio_keys_report_state (struct gpio_keys_drvdata *ddata)
@@ -573,28 +566,20 @@ gpio_keys_get_devtree_pdata(struct device *dev)struct device_node *node, *pp;struct gpio_keys_platform_data *pdata;struct gpio_keys_button *button; -int error; -int nbuttons; -int i; +int i, nbuttons; node = dev->of_node; -if (!node) { - error = -ENODEV ; - goto err_out; - } +if (!node) +return ERR_PTR (-ENODEV ); nbuttons =of_get_child_count (node); -if (nbuttons ==0 ) { - error = -ENODEV ; - goto err_out; - } +if (nbuttons ==0 ) +return ERR_PTR (-ENODEV ); - pdata =kzalloc (sizeof (*pdata) + nbuttons * (sizeof *button), -GFP_KERNEL ); -if (!pdata) { - error = -ENOMEM ; - goto err_out; - } + pdata =devm_kzalloc (dev,sizeof (*pdata) + nbuttons *sizeof (*button), +GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); pdata->buttons = (struct gpio_keys_button *)(pdata +1 ); pdata->nbuttons = nbuttons;
@@ -614,12 +599,11 @@ gpio_keys_get_devtree_pdata(struct device *dev) gpio =of_get_gpio_flags (pp,0 , &flags);if (gpio <0 ) { - error = gpio; -if (error != -EPROBE_DEFER ) +if (gpio != -EPROBE_DEFER )dev_err (dev,"Failed to get gpio flags, error: %d\n" , - error); - goto err_free_pdata; + gpio); +return ERR_PTR (gpio); } button = &pdata->buttons[i++];
@@ -630,8 +614,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)if (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); } button->desc =of_get_property (pp,"label" ,NULL );
@@ -646,17 +629,10 @@ gpio_keys_get_devtree_pdata(struct device *dev) button->debounce_interval =5 ; } -if (pdata->nbuttons ==0 ) { - error = -EINVAL ; - goto err_free_pdata; - } +if (!pdata->nbuttons) +return ERR_PTR (-EINVAL );return pdata; - -err_free_pdata: -kfree (pdata); -err_out: -return ERR_PTR (error); }static struct of_device_id gpio_keys_of_match[] = {
@@ -681,8 +657,6 @@ static void gpio_remove_key(struct gpio_button_data *bdata)if (bdata->timer_debounce)del_timer_sync (&bdata->timer);cancel_work_sync (&bdata->work); -if (gpio_is_valid (bdata->button->gpio)) -gpio_free (bdata->button->gpio); }static int gpio_keys_probe (struct platform_device *pdev)
@@ -700,14 +674,13 @@ static int gpio_keys_probe(struct platform_device *pdev)return PTR_ERR (pdata); } - ddata =kzalloc (sizeof (struct gpio_keys_drvdata ) + - pdata->nbuttons *sizeof (struct gpio_button_data ), -GFP_KERNEL ); - input =input_allocate_device (); + ddata =devm_kzalloc (&pdev->dev,sizeof (struct gpio_keys_drvdata ) + + pdata->nbuttons *sizeof (struct gpio_button_data ), +GFP_KERNEL ); + input =devm_input_allocate_device (&pdev->dev);if (!ddata || !input) {dev_err (dev,"failed to allocate state\n" ); - error = -ENOMEM ; - goto fail1; +return -ENOMEM ; } ddata->pdata = pdata;
@@ -768,13 +741,6 @@ static int gpio_keys_probe(struct platform_device *pdev)while (--i >=0 )gpio_remove_key (&ddata->data[i]); - fail1: -input_free_device (input); -kfree (ddata); -/* If we have no platform data, we allocated pdata dynamically. */ -if (!dev_get_platdata (&pdev->dev)) -kfree (pdata); -return error; }
@@ -793,12 +759,6 @@ static int gpio_keys_remove(struct platform_device *pdev)input_unregister_device (input); -/* If we have no platform data, we allocated pdata dynamically. */ -if (!dev_get_platdata (&pdev->dev)) -kfree (ddata->pdata); - -kfree (ddata); -return 0 ; }
Signature · 1 line
1.8.3.2
Dmitry Torokhov
maintainerRe: [PATCH RESEND 2/2] input: gpio_keys: Convert to devm-* API
Hi Alexander,
Quoted 36 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_oneinput_allocate_device->devm_input_allocate_deviceSigned-off-by Alexander Shiyan <[email protected]>--- drivers/input/keyboard/gpio_keys.c | 96 +++++++++++--------------------------- 1 file changed, 28 insertions(+), 68 deletions(-)drivers/input/keyboard/gpio_keys.c +3
-2@@ -433,7 +433,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev,struct device *dev = &pdev->dev;irq_handler_t isr;unsigned long irqflags; -int irq, error; +int error; bdata->input = input; bdata->button = button;@@ -441,7 +441,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,if (gpio_is_valid (button->gpio)) { - error =gpio_request_one (button->gpio,GPIOF_IN , desc); + error =devm_gpio_request_one (&pdev->dev, button->gpio, +GPIOF_IN , desc);if (error <0 ) {dev_err (dev,"Failed to request GPIO %d, error %d\n" , button->gpio, error);
drivers/input/keyboard/gpio_keys.c static int gpio_keys_setup_key(struct platform_device *pdev, · line 462
Quoted 8 lines
drivers/input/keyboard/gpio_keys.c +2
-3@@ -457,15 +458,13 @@ static int gpio_keys_setup_key(struct platform_device *pdev, button->debounce_interval; } - irq =gpio_to_irq (button->gpio); -if (irq <0 ) { - error = irq; + bdata->irq =gpio_to_irq (button->gpio); +if (bdata->irq <0 ) {
This is wrong, bdata->irq is unsigned.
Also I already applied the earlier version of the patch dealing with non-gpio resources. How about the patch below?
Thanks.
Signature · 16 lines
Dmitry Input: gpio_keys - more conversions to devm-* API From: Alexander Shiyan <[email protected]> Replace existing gpio resource handling in the driver with managed resources, this ensures more consistent error values and simplifies error paths. Signed-off-by: Alexander Shiyan <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/input/keyboard/gpio_keys.c | 69 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 35 deletions(-)
drivers/input/keyboard/gpio_keys.c +34 -35
@@ -424,6 +424,16 @@ out:return IRQ_HANDLED ; } +static void gpio_keys_quiesce_key (void *data) +{ +struct gpio_button_data *bdata = data; + +if (bdata->timer_debounce) +del_timer_sync (&bdata->timer); + +cancel_work_sync (&bdata->work); +} + static int gpio_keys_setup_key(struct platform_device *pdev, struct input_dev *input, struct gpio_button_data *bdata,
@@ -433,7 +443,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,struct device *dev = &pdev->dev;irq_handler_t isr;unsigned long irqflags; -int irq, error; +int irq; +int error; bdata->input = input; bdata->button = button;
@@ -441,7 +452,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,if (gpio_is_valid (button->gpio)) { - error =gpio_request_one (button->gpio,GPIOF_IN , desc); + error =devm_gpio_request_one (&pdev->dev, button->gpio, +GPIOF_IN , desc);if (error <0 ) {dev_err (dev,"Failed to request GPIO %d, error %d\n" , button->gpio, error);
@@ -463,7 +475,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev,dev_err (dev,"Unable to get irq number for GPIO %d, error %d\n" , button->gpio, error); - goto fail; +return error; } bdata->irq = irq;
@@ -497,26 +509,33 @@ static int gpio_keys_setup_key(struct platform_device *pdev,input_set_capability (input, button->type ?:EV_KEY , button->code);/* +* Install custom action to cancel debounce timer and +* workqueue item. +*/ + error =devm_add_action (&pdev->dev, gpio_keys_quiesce_key, bdata); +if (error) { +dev_err (&pdev->dev, +"failed to register quiesce action, error: %d\n" , + error); +return error; + } + +/* * If platform has specified that the button can be disabled, * we don't want it to share the interrupt line. */ if (!button->can_disable) irqflags |=IRQF_SHARED ; - error =request_any_context_irq (bdata->irq, isr, irqflags, desc, bdata); + error =devm_request_any_context_irq (&pdev->dev, bdata->irq, + isr, irqflags, desc, bdata);if (error <0 ) {dev_err (dev,"Unable to claim irq %d; error %d\n" , bdata->irq, error); - goto fail; +return error; }return 0 ; - -fail: -if (gpio_is_valid (button->gpio)) -gpio_free (button->gpio); - -return error; }static void gpio_keys_report_state (struct gpio_keys_drvdata *ddata)
@@ -662,16 +681,6 @@ gpio_keys_get_devtree_pdata(struct device *dev)#endif -static void gpio_remove_key (struct gpio_button_data *bdata) -{ -free_irq (bdata->irq, bdata); -if (bdata->timer_debounce) -del_timer_sync (&bdata->timer); -cancel_work_sync (&bdata->work); -if (gpio_is_valid (bdata->button->gpio)) -gpio_free (bdata->button->gpio); -} -static int gpio_keys_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -730,7 +739,7 @@ static int gpio_keys_probe(struct platform_device *pdev) error =gpio_keys_setup_key (pdev, input, bdata, button);if (error) - goto fail2; +return error;if (button->wakeup) wakeup =1 ;
@@ -740,41 +749,31 @@ static int gpio_keys_probe(struct platform_device *pdev)if (error) {dev_err (dev,"Unable to export keys/switches, error: %d\n" , error); - goto fail2; +return error; } error =input_register_device (input);if (error) {dev_err (dev,"Unable to register input device, error: %d\n" , error); - goto fail3; + goto err_remove_group; }device_init_wakeup (&pdev->dev, wakeup);return 0 ; - fail3: +err_remove_group:sysfs_remove_group (&pdev->dev.kobj, &gpio_keys_attr_group); - fail2: -while (--i >=0 ) -gpio_remove_key (&ddata->data[i]); -return error; }static int gpio_keys_remove (struct platform_device *pdev) { -struct gpio_keys_drvdata *ddata =platform_get_drvdata (pdev); -int i; -sysfs_remove_group (&pdev->dev.kobj, &gpio_keys_attr_group);device_init_wakeup (&pdev->dev,0 ); -for (i =0 ; i < ddata->pdata->nbuttons; i++) -gpio_remove_key (&ddata->data[i]); -return 0 ; }
Dmitry Torokhov
maintainerHi Alexander,
Quoted 6 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one
If we are doing the conversion can we go all the Alexanderway (needs the other 2 patches I just posted and CCed you)?
Thanks.
Signature · 19 lines
Dmitry Input: gpio_keys_polled - convert to devm-* API From: Alexander Shiyan <[email protected]> Replace existing resource handling in the driver with managed device resources, this ensures more consistent error values and simplifies error handling paths: kzalloc -> devm_kzalloc gpio_request_one -> devm_gpio_request_one input_allocate_polled_device -> devm_input_allocate_polled_device Signed-off-by: Alexander Shiyan <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> --- drivers/input/keyboard/gpio_keys_polled.c | 98 ++++++----------------------- 1 file changed, 21 insertions(+), 77 deletions(-)
drivers/input/keyboard/gpio_keys_polled.c +21 -77
@@ -120,12 +120,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (nbuttons ==0 )return NULL ; - pdata =kzalloc (sizeof (*pdata) + nbuttons * (sizeof *button), -GFP_KERNEL ); -if (!pdata) { - error = -ENOMEM ; - goto err_out; - } + pdata =devm_kzalloc (dev,sizeof (*pdata) + nbuttons *sizeof (*button), +GFP_KERNEL ); +if (!pdata) +return ERR_PTR (-ENOMEM ); pdata->buttons = (struct gpio_keys_button *)(pdata +1 ); pdata->nbuttons = nbuttons;
@@ -151,7 +149,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structdev_err (dev,"Failed to get gpio flags, error: %d\n" , error); - goto err_free_pdata; +return ERR_PTR (error); } button = &pdata->buttons[i++];
@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); } button->desc =of_get_property (pp,"label" ,NULL );
@@ -178,17 +175,10 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct button->debounce_interval =5 ; } -if (pdata->nbuttons ==0 ) { - error = -EINVAL ; - goto err_free_pdata; - } +if (pdata->nbuttons ==0 ) +return ERR_PTR (-EINVAL );return pdata; - -err_free_pdata: -kfree (pdata); -err_out: -return ERR_PTR (error); }static struct of_device_id gpio_keys_polled_of_match[] = {
@@ -213,6 +203,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)struct gpio_keys_polled_dev *bdev;struct input_polled_dev *poll_dev;struct input_dev *input; +size_t size;int error;int i;
@@ -228,24 +219,21 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)if (!pdata->poll_interval) {dev_err (dev,"missing poll_interval value\n" ); - error = -EINVAL ; - goto err_free_pdata; +return -EINVAL ; } - bdev =kzalloc (sizeof (struct gpio_keys_polled_dev ) + - pdata->nbuttons *sizeof (struct gpio_keys_button_data ), -GFP_KERNEL ); + size =sizeof (struct gpio_keys_polled_dev ) + + pdata->nbuttons *sizeof (struct gpio_keys_button_data ); + bdev =devm_kzalloc (&pdev->dev, size,GFP_KERNEL );if (!bdev) {dev_err (dev,"no memory for private data\n" ); - error = -ENOMEM ; - goto err_free_pdata; +return -ENOMEM ; } - poll_dev =input_allocate_polled_device (); + poll_dev =devm_input_allocate_polled_device (&pdev->dev);if (!poll_dev) {dev_err (dev,"no memory for polled device\n" ); - error = -ENOMEM ; - goto err_free_bdev; +return -ENOMEM ; } poll_dev->private = bdev;
@@ -258,7 +246,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) input->name = pdev->name; input->phys =DRV_NAME "/input0" ; - input->dev.parent = &pdev->dev; input->id.bustype =BUS_HOST ; input->id.vendor =0x0001 ;
@@ -277,16 +264,15 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)if (button->wakeup) {dev_err (dev,DRV_NAME " does not support wakeup\n" ); - error = -EINVAL ; - goto err_free_gpio; +return -EINVAL ; } - error =gpio_request_one (gpio,GPIOF_IN , - button->desc ?:DRV_NAME ); + error =devm_gpio_request_one (&pdev->dev, gpio,GPIOF_IN , + button->desc ? :DRV_NAME );if (error) {dev_err (dev,"unable to claim gpio %u, err=%d\n" , gpio, error); - goto err_free_gpio; +return error; } bdata->can_sleep =gpio_cansleep (gpio);
@@ -306,7 +292,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)if (error) {dev_err (dev,"unable to register polled device, err=%d\n" , error); - goto err_free_gpio; +return error; }/* report initial state of the buttons */
@@ -315,52 +301,10 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) &bdev->data[i]);return 0 ; - -err_free_gpio: -while (--i >=0 ) -gpio_free (pdata->buttons[i].gpio); - -input_free_polled_device (poll_dev); - -err_free_bdev: -kfree (bdev); - -err_free_pdata: -/* If we have no platform_data, we allocated pdata dynamically. */ -if (!dev_get_platdata (&pdev->dev)) -kfree (pdata); - -return error; -} - -static int gpio_keys_polled_remove (struct platform_device *pdev) -{ -struct gpio_keys_polled_dev *bdev =platform_get_drvdata (pdev); -const struct gpio_keys_platform_data *pdata = bdev->pdata; -int i; - -input_unregister_polled_device (bdev->poll_dev); - -for (i =0 ; i < pdata->nbuttons; i++) -gpio_free (pdata->buttons[i].gpio); - -input_free_polled_device (bdev->poll_dev); - -/* -* If we had no platform_data, we allocated pdata dynamically and -* must free it here. -*/ -if (!dev_get_platdata (&pdev->dev)) -kfree (pdata); - -kfree (bdev); - -return 0 ; }static struct platform_driver gpio_keys_polled_driver = { .probe = gpio_keys_polled_probe, - .remove = gpio_keys_polled_remove, .driver = { .name =DRV_NAME , .owner =THIS_MODULE ,
Mon, 28 Apr 2014 20:26:00 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 33 lines
Hi Alexander,
Quoted 6 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_oneIf we are doing the conversion can we go all the Alexanderway (needs the other 2 patches I just posted and CCed you)?
Thanks.
Signature · 17 lines
Dmitry Input: gpio_keys_polled - convert to devm-* API From: Alexander Shiyan <[email protected]> Replace existing resource handling in the driver with managed device resources, this ensures more consistent error values and simplifies error handling paths: kzalloc -> devm_kzalloc gpio_request_one -> devm_gpio_request_one input_allocate_polled_device -> devm_input_allocate_polled_device Signed-off-by: Alexander Shiyan <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> ---
...
drivers/input/keyboard/gpio_keys_polled.c static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
drivers/input/keyboard/gpio_keys_polled.c +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); }
We can even use return value from of_property_read_u32() on error.
All other looks OK.
---
Dmitry Torokhov
maintainerQuoted 46 lines · Alexander Shiyan
Mon, 28 Apr 2014 20:26:00 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 33 lines
Hi Alexander,
Quoted 6 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_oneIf we are doing the conversion can we go all the Alexanderway (needs the other 2 patches I just posted and CCed you)?
Thanks.
Signature · 17 lines
Dmitry Input: gpio_keys_polled - convert to devm-* API From: Alexander Shiyan <[email protected]> Replace existing resource handling in the driver with managed device resources, this ensures more consistent error values and simplifies error handling paths: kzalloc -> devm_kzalloc gpio_request_one -> devm_gpio_request_one input_allocate_polled_device -> devm_input_allocate_polled_device Signed-off-by: Alexander Shiyan <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> ---...
drivers/input/keyboard/gpio_keys_polled.c static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
drivers/input/keyboard/gpio_keys_polled.c +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); }We can even use return value from
of_property_read_u32()on error.
Quoted 1 line
All other looks OK.
Do you have hardware that uses gpio_keys_polled?
Thanks.
Signature · 5 lines
Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tue, 29 Apr 2014 08:50:32 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 10 lines · Alexander Shiyan
Quoted 9 lines
Mon, 28 Apr 2014 20:26:00 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 8 lines
Hi Alexander,
Quoted 5 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one
...
Quoted 11 lines
Quoted 11 lines
drivers/input/keyboard/gpio_keys_polled.c static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
drivers/input/keyboard/gpio_keys_polled.c +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); }We can even use return value from
of_property_read_u32()on error.
Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?
Yes.
---
Dmitry Torokhov
maintainerQuoted 23 lines · Alexander Shiyan
Tue, 29 Apr 2014 08:50:32 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 10 lines · Alexander Shiyan
Quoted 9 lines
Mon, 28 Apr 2014 20:26:00 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 8 lines
Hi Alexander,
Quoted 5 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 11 lines
Quoted 11 lines
drivers/input/keyboard/gpio_keys_polled.c static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
drivers/input/keyboard/gpio_keys_polled.c +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); }We can even use return value from
of_property_read_u32()on error.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?Yes.
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Thanks.
Signature · 5 lines
Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tue, 29 Apr 2014 09:19:27 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 24 lines · Alexander Shiyan
Quoted 23 lines
Tue, 29 Apr 2014 08:50:32 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 10 lines · Alexander Shiyan
Quoted 9 lines
Mon, 28 Apr 2014 20:26:00 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 8 lines
Hi Alexander,
Quoted 5 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 11 lines
Quoted 11 lines
drivers/input/keyboard/gpio_keys_polled.c static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
drivers/input/keyboard/gpio_keys_polled.c +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); }We can even use return value from
of_property_read_u32()on error.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?Yes.
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Unfortunately, due to the large following weekends, I cannot do it earlier than 2 weeks.
---
Dmitry Torokhov
maintainerQuoted 29 lines · Alexander Shiyan
Tue, 29 Apr 2014 09:19:27 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 28 lines · Alexander Shiyan
Quoted 27 lines
Tue, 29 Apr 2014 08:50:32 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 10 lines · Alexander Shiyan
Quoted 9 lines
Mon, 28 Apr 2014 20:26:00 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 8 lines
Hi Alexander,
Quoted 5 lines · Alexander Shiyan
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 14 lines
Quoted 11 lines
drivers/input/keyboard/gpio_keys_polled.c static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
drivers/input/keyboard/gpio_keys_polled.c +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structif (of_property_read_u32 (pp,"linux,code" , &button->code)) {dev_err (dev,"Button without keycode: 0x%x\n" , button->gpio); - error = -EINVAL ; - goto err_free_pdata; +return ERR_PTR (-EINVAL ); }We can even use return value from
of_property_read_u32()on error.Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Yes.
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Unfortunately, due to the large following weekends, I cannot do it earlier than 2 weeks.
That is fine, there is no rush.
Signature · 5 lines
Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Tue, 29 Apr 2014 09:36:49 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 1 line · Alexander Shiyan
...
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 11 lines
Quoted 11 lines
Review static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
(quoted diff) +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct if (of_property_read_u32(pp, "linux,code", &button->code)) { dev_err(dev, "Button without keycode: 0x%x\n", button->gpio); - error = -EINVAL; - goto err_free_pdata; + return ERR_PTR(-EINVAL); }We can even use return value from
of_property_read_u32()on error.Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?Yes.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Unfortunately, due to the large following weekends, I cannot do it earlier than 2 weeks.
That is fine, there is no rush.
OK. In this case it would be nice to have a separate branch with poll-series and this patch. Can you make it?
---
Dmitry Torokhov
maintainerQuoted 30 lines · Alexander Shiyan
Tue, 29 Apr 2014 09:36:49 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 1 line · Alexander Shiyan
...
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 11 lines
Quoted 11 lines
Review static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
(quoted diff) +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct if (of_property_read_u32(pp, "linux,code", &button->code)) { dev_err(dev, "Button without keycode: 0x%x\n", button->gpio); - error = -EINVAL; - goto err_free_pdata; + return ERR_PTR(-EINVAL); }We can even use return value from
of_property_read_u32()on error.Quoted 5 lines
Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?Yes.
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Unfortunately, due to the large following weekends, I cannot do it earlier than 2 weeks.
That is fine, there is no rush.
OK. In this case it would be nice to have a separate branch with poll-series and this patch. Can you make it?
I just pushed new input-polldev branch containing input polldev changes and your patches to gpio-keys and gpio-keys-polled. It is based on 3.14.
Thanks.
Signature · 5 lines
Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Alexander Shiyan
Tested-byMon, 5 May 2014 21:18:18 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 34 lines · Alexander Shiyan
Quoted 33 lines
Tue, 29 Apr 2014 09:36:49 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 1 line · Alexander Shiyan
...
Quoted 30 lines
Quoted 29 lines
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 11 lines
Quoted 11 lines
Review static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
(quoted diff) +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct if (of_property_read_u32(pp, "linux,code", &button->code)) { dev_err(dev, "Button without keycode: 0x%x\n", button->gpio); - error = -EINVAL; - goto err_free_pdata; + return ERR_PTR(-EINVAL); }We can even use return value from
of_property_read_u32()on error.Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?Yes.
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Unfortunately, due to the large following weekends, I cannot do it earlier than 2 weeks.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
That is fine, there is no rush.
OK. In this case it would be nice to have a separate branch with poll-series and this patch. Can you make it?
I just pushed new input-polldev branch containing input polldev changes and your patches to gpio-keys and gpio-keys-polled. It is based on 3.14.
This works for me as expected, so:
---
Dmitry Torokhov
maintainerQuoted 40 lines · Alexander Shiyan
Mon, 5 May 2014 21:18:18 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 39 lines · Alexander Shiyan
Quoted 37 lines
Tue, 29 Apr 2014 09:36:49 -0700 от Dmitry Torokhov <[email protected]>:
Quoted 1 line · Alexander Shiyan
...
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
Replace existing resource handling in the driver with managed device resource, this ensures more consistent error values and simplifies error paths.
kzalloc ->devm_kzallocgpio_request_one->devm_gpio_request_one...
Quoted 11 lines
Quoted 11 lines
Review static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct · line 164
Quoted 8 lines
(quoted diff) +1
-2@@ -162,8 +160,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct if (of_property_read_u32(pp, "linux,code", &button->code)) { dev_err(dev, "Button without keycode: 0x%x\n", button->gpio); - error = -EINVAL; - goto err_free_pdata; + return ERR_PTR(-EINVAL); }We can even use return value from
of_property_read_u32()on error.Quoted 3 lines
Quoted 1 line
All other looks OK.
Do you have hardware that uses
gpio_keys_polled?Yes.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
So did you have a chance to actually try my version(s)? I would feel much better if you had ;)
Unfortunately, due to the large following weekends, I cannot do it earlier than 2 weeks.
That is fine, there is no rush.
OK. In this case it would be nice to have a separate branch with poll-series and this patch. Can you make it?
Quoted 6 lines
Quoted 2 lines
I just pushed new input-polldev branch containing input polldev changes and your patches to gpio-keys and gpio-keys-polled. It is based on 3.14.
This works for me as expected, so:
Tested-by Alexander Shiyan <[email protected]>
Thank you Alexander, I queued them all for the next merge window.
Signature · 5 lines
Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html