* [PATCH] pinctrl: sh-pfc: Make legacy function GPIO handling less fragile
@ 2019-11-13 10:18 Geert Uytterhoeven
2019-11-14 7:06 ` Niklas Söderlund
0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2019-11-13 10:18 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-renesas-soc, linux-gpio, Geert Uytterhoeven
If there are no function GPIOs, sh_pfc_register_gpiochip() returns early
with a success indicator. This is fragile, as new code may be added
after the #ifdef block, which won't be executed in case of early return.
Invert the logic, so the code always continues until the end of the
function on success.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
To be queued in sh-pfc-for-v5.6.
drivers/pinctrl/sh-pfc/gpio.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c
index 5a55b8da7919520e..8213e118aa408573 100644
--- a/drivers/pinctrl/sh-pfc/gpio.c
+++ b/drivers/pinctrl/sh-pfc/gpio.c
@@ -386,12 +386,11 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
}
/* Register the function GPIOs chip. */
- if (pfc->info->nr_func_gpios == 0)
- return 0;
-
- chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup, NULL);
- if (IS_ERR(chip))
- return PTR_ERR(chip);
+ if (pfc->info->nr_func_gpios) {
+ chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup, NULL);
+ if (IS_ERR(chip))
+ return PTR_ERR(chip);
+ }
#endif /* CONFIG_PINCTRL_SH_FUNC_GPIO */
return 0;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pinctrl: sh-pfc: Make legacy function GPIO handling less fragile
2019-11-13 10:18 [PATCH] pinctrl: sh-pfc: Make legacy function GPIO handling less fragile Geert Uytterhoeven
@ 2019-11-14 7:06 ` Niklas Söderlund
0 siblings, 0 replies; 2+ messages in thread
From: Niklas Söderlund @ 2019-11-14 7:06 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Linus Walleij, linux-renesas-soc, linux-gpio
Hi Geert,
Thanks for your work.
On 2019-11-13 11:18:09 +0100, Geert Uytterhoeven wrote:
> If there are no function GPIOs, sh_pfc_register_gpiochip() returns early
> with a success indicator. This is fragile, as new code may be added
> after the #ifdef block, which won't be executed in case of early return.
>
> Invert the logic, so the code always continues until the end of the
> function on success.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> To be queued in sh-pfc-for-v5.6.
>
> drivers/pinctrl/sh-pfc/gpio.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pinctrl/sh-pfc/gpio.c b/drivers/pinctrl/sh-pfc/gpio.c
> index 5a55b8da7919520e..8213e118aa408573 100644
> --- a/drivers/pinctrl/sh-pfc/gpio.c
> +++ b/drivers/pinctrl/sh-pfc/gpio.c
> @@ -386,12 +386,11 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
> }
>
> /* Register the function GPIOs chip. */
> - if (pfc->info->nr_func_gpios == 0)
> - return 0;
> -
> - chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup, NULL);
> - if (IS_ERR(chip))
> - return PTR_ERR(chip);
> + if (pfc->info->nr_func_gpios) {
> + chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup, NULL);
> + if (IS_ERR(chip))
> + return PTR_ERR(chip);
> + }
> #endif /* CONFIG_PINCTRL_SH_FUNC_GPIO */
>
> return 0;
> --
> 2.17.1
>
--
Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-14 7:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 10:18 [PATCH] pinctrl: sh-pfc: Make legacy function GPIO handling less fragile Geert Uytterhoeven
2019-11-14 7:06 ` Niklas Söderlund
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).