pinctrl: pistachio: Use common error handling code in pistachio_gpio_register()

Message ID 0b8eced6-c4d9-6b0b-ac23-de764622e91c@users.sourceforge.net
State New
Headers show
Series
  • pinctrl: pistachio: Use common error handling code in pistachio_gpio_register()
Related show

Commit Message

SF Markus Elfring Oct. 30, 2017, 5:51 p.m.
From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/pinctrl/pinctrl-pistachio.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Andrew Bresticker Oct. 31, 2017, 4:13 p.m. | #1
Markus,

On Mon, Oct 30, 2017 at 10:51 AM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Acked-by: Andrew Bresticker <abrestic@chromium.org>

> ---
>  drivers/pinctrl/pinctrl-pistachio.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c
> index 55375b1b3cc8..b314eb61bf35 100644
> --- a/drivers/pinctrl/pinctrl-pistachio.c
> +++ b/drivers/pinctrl/pinctrl-pistachio.c
> @@ -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
>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter Nov. 1, 2017, 10:18 a.m. | #2
On Mon, Oct 30, 2017 at 06:51:19PM +0100, SF Markus Elfring wrote:
> @@ -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.


>  		}
>  	}
>  
>  	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

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c
index 55375b1b3cc8..b314eb61bf35 100644
--- a/drivers/pinctrl/pinctrl-pistachio.c
+++ b/drivers/pinctrl/pinctrl-pistachio.c
@@ -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);