pinctrl: pistachio: Use common error handling code in pistachio_gpio_register()
Subsystems (3)
PATCH 1/1 pinctrl: pistachio: Use common error handling code in pistachio_gpio_register()
From: Markus Elfring <[email protected]>
Date: Mon, 30 Oct 2017 18:40:10 +0100
Adjust jump targets so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
--- drivers/pinctrl/pinctrl-pistachio.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/pinctrl/pinctrl-pistachio.c +10 -9
@@ -1362,21 +1362,21 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (!child) {dev_err (pctl->dev,"No node for bank %u\n" , i); ret = -ENODEV ; - goto err; + goto remove_chips; }if (!of_find_property (child,"gpio-controller" ,NULL )) {dev_err (pctl->dev,"No gpio-controller property for bank %u\n" , i); ret = -ENODEV ; - goto err; + goto remove_chips; } irq =irq_of_parse_and_map (child,0 );if (irq <0 ) {dev_err (pctl->dev,"No IRQ for bank %u: %d\n" , i, irq); ret = irq; - goto err; + goto remove_chips; } bank = &pctl->gpio_banks[i];
@@ -1389,7 +1389,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add GPIO chip %u: %d\n" , i, ret); - goto err; + goto remove_chips; } ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip,
@@ -1397,8 +1397,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add IRQ chip %u: %d\n" , i, ret); -gpiochip_remove (&bank->gpio_chip); - goto err; + goto remove_chip; }gpiochip_set_chained_irqchip (&bank->gpio_chip, &bank->irq_chip, irq, pistachio_gpio_irq_handler);
@@ -1409,13 +1408,15 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add GPIO range %u: %d\n" , i, ret); -gpiochip_remove (&bank->gpio_chip); - goto err; + goto remove_chip; } }return 0 ; -err: + +remove_chip: +gpiochip_remove (&bank->gpio_chip); +remove_chips:for (; i >0 ; i--) { bank = &pctl->gpio_banks[i -1 ];gpiochip_remove (&bank->gpio_chip);
Signature · 1 line
2.14.3
Markus,
Quoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 30 Oct 2017 18:40:10 +0100Adjust jump targets so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Quoted 74 lines
--- drivers/pinctrl/pinctrl-pistachio.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)drivers/pinctrl/pinctrl-pistachio.c +10
-10@@ -1362,21 +1362,21 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (!child) {dev_err (pctl->dev,"No node for bank %u\n" , i); ret = -ENODEV ; - goto err; + goto remove_chips; }if (!of_find_property (child,"gpio-controller" ,NULL )) {dev_err (pctl->dev,"No gpio-controller property for bank %u\n" , i); ret = -ENODEV ; - goto err; + goto remove_chips; } irq =irq_of_parse_and_map (child,0 );if (irq <0 ) {dev_err (pctl->dev,"No IRQ for bank %u: %d\n" , i, irq); ret = irq; - goto err; + goto remove_chips; } bank = &pctl->gpio_banks[i];@@ -1389,7 +1389,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add GPIO chip %u: %d\n" , i, ret); - goto err; + goto remove_chips; } ret = gpiochip_irqchip_add(&bank->gpio_chip, &bank->irq_chip,@@ -1397,8 +1397,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add IRQ chip %u: %d\n" , i, ret); -gpiochip_remove (&bank->gpio_chip); - goto err; + goto remove_chip; }gpiochip_set_chained_irqchip (&bank->gpio_chip, &bank->irq_chip, irq, pistachio_gpio_irq_handler);@@ -1409,13 +1408,15 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add GPIO range %u: %d\n" , i, ret); -gpiochip_remove (&bank->gpio_chip); - goto err; + goto remove_chip; } }return 0 ; -err: + +remove_chip: +gpiochip_remove (&bank->gpio_chip); +remove_chips:for (; i >0 ; i--) { bank = &pctl->gpio_banks[i -1 ];gpiochip_remove (&bank->gpio_chip); --2.14.3
drivers/pinctrl/pinctrl-pistachio.c static int pistachio_gpio_register(struct pistachio_pinctrl *pctl) · line 1411
Quoted 7 lines · SF Markus Elfring
drivers/pinctrl/pinctrl-pistachio.c +1
-2@@ -1409,13 +1408,15 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)if (ret <0 ) {dev_err (pctl->dev,"Failed to add GPIO range %u: %d\n" , i, ret); -gpiochip_remove (&bank->gpio_chip); - goto err; + goto remove_chip;
It's better code to put the gpiochip_remove() before the goto, because say we want to add more error handling before the remove_chip: label. Now it doesn't work.
drivers/pinctrl/pinctrl-pistachio.c static int pistachio_gpio_register(struct pistachio_pinctrl *pctl) · line 1422
Quoted 12 lines
drivers/pinctrl/pinctrl-pistachio.c +4
-1} }return 0 ; -err: + +remove_chip: +gpiochip_remove (&bank->gpio_chip); +remove_chips:for (; i >0 ; i--) { bank = &pctl->gpio_banks[i -1 ];gpiochip_remove (&bank->gpio_chip);
regards,
dan carpenter