linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
@ 2017-10-30 18:36 SF Markus Elfring
  2017-10-30 19:15 ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-10-30 18:36 UTC (permalink / raw)
  To: linux-gpio, linux-arm-kernel, Barry Song, Geert Uytterhoeven,
	Julia Lawall, Krzysztof Kozlowski, Linus Walleij,
	Ludovic Desroches, Patrice Chotard, Rob Herring
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 30 Oct 2017 19:26:56 +0100

Add a jump target 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/sirf/pinctrl-sirf.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/sirf/pinctrl-sirf.c b/drivers/pinctrl/sirf/pinctrl-sirf.c
index d64add0b84cc..5ec2f37f5180 100644
--- a/drivers/pinctrl/sirf/pinctrl-sirf.c
+++ b/drivers/pinctrl/sirf/pinctrl-sirf.c
@@ -89,16 +89,12 @@ static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev,
 	/* calculate number of maps required */
 	for_each_child_of_node(np_config, np) {
 		ret = of_property_read_string(np, "sirf,function", &function);
-		if (ret < 0) {
-			of_node_put(np);
-			return ret;
-		}
+		if (ret < 0)
+			goto put_node;
 
 		ret = of_property_count_strings(np, "sirf,pins");
-		if (ret < 0) {
-			of_node_put(np);
-			return ret;
-		}
+		if (ret < 0)
+			goto put_node;
 
 		count += ret;
 	}
@@ -125,6 +121,10 @@ static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev,
 	*num_maps = count;
 
 	return 0;
+
+put_node:
+	of_node_put(np);
+	return ret;
 }
 
 static void sirfsoc_dt_free_map(struct pinctrl_dev *pctldev,
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
  2017-10-30 18:36 [PATCH] pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map() SF Markus Elfring
@ 2017-10-30 19:15 ` Geert Uytterhoeven
  2017-10-30 19:32   ` SF Markus Elfring
  2017-11-01 10:33   ` [PATCH] " Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2017-10-30 19:15 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-gpio, linux-arm-kernel, Barry Song, Geert Uytterhoeven,
	Julia Lawall, Krzysztof Kozlowski, Linus Walleij,
	Ludovic Desroches, Patrice Chotard, Rob Herring, LKML,
	kernel-janitors

Hi Markus,

On Mon, Oct 30, 2017 at 7:36 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Mon, 30 Oct 2017 19:26:56 +0100
>
> Add a jump target 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.

Does Coccinelle have a threshold for how much cleanup can be shared?

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

Again, breaking the flow for the reviewer isn't worth it here, IMHO.

> diff --git a/drivers/pinctrl/sirf/pinctrl-sirf.c b/drivers/pinctrl/sirf/pinctrl-sirf.c
> index d64add0b84cc..5ec2f37f5180 100644
> --- a/drivers/pinctrl/sirf/pinctrl-sirf.c
> +++ b/drivers/pinctrl/sirf/pinctrl-sirf.c
> @@ -89,16 +89,12 @@ static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev,
>         /* calculate number of maps required */
>         for_each_child_of_node(np_config, np) {
>                 ret = of_property_read_string(np, "sirf,function", &function);
> -               if (ret < 0) {
> -                       of_node_put(np);
> -                       return ret;
> -               }
> +               if (ret < 0)
> +                       goto put_node;
>
>                 ret = of_property_count_strings(np, "sirf,pins");
> -               if (ret < 0) {
> -                       of_node_put(np);
> -                       return ret;
> -               }
> +               if (ret < 0)
> +                       goto put_node;
>
>                 count += ret;
>         }
> @@ -125,6 +121,10 @@ static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev,
>         *num_maps = count;
>
>         return 0;
> +
> +put_node:
> +       of_node_put(np);
> +       return ret;
>  }

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
  2017-10-30 19:15 ` Geert Uytterhoeven
@ 2017-10-30 19:32   ` SF Markus Elfring
  2017-10-30 19:34     ` Geert Uytterhoeven
  2017-11-01 10:33   ` [PATCH] " Dan Carpenter
  1 sibling, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-10-30 19:32 UTC (permalink / raw)
  To: Geert Uytterhoeven, linux-gpio, linux-arm-kernel
  Cc: Barry Song, Geert Uytterhoeven, Julia Lawall,
	Krzysztof Kozlowski, Linus Walleij, Ludovic Desroches,
	Patrice Chotard, Rob Herring, LKML, kernel-janitors

>> Add a jump target 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.
> 
> Does Coccinelle have a threshold for how much cleanup can be shared?

Are you looking for a limitation of such source code search patterns?

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
  2017-10-30 19:32   ` SF Markus Elfring
@ 2017-10-30 19:34     ` Geert Uytterhoeven
  2017-10-30 19:41       ` SF Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2017-10-30 19:34 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-gpio, linux-arm-kernel, Barry Song, Geert Uytterhoeven,
	Julia Lawall, Krzysztof Kozlowski, Linus Walleij,
	Ludovic Desroches, Patrice Chotard, Rob Herring, LKML,
	kernel-janitors

On Mon, Oct 30, 2017 at 8:32 PM, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
>>> Add a jump target 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.
>>
>> Does Coccinelle have a threshold for how much cleanup can be shared?
>
> Are you looking for a limitation of such source code search patterns?

Exactly.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
  2017-10-30 19:34     ` Geert Uytterhoeven
@ 2017-10-30 19:41       ` SF Markus Elfring
  0 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-10-30 19:41 UTC (permalink / raw)
  To: Geert Uytterhoeven, linux-gpio, linux-arm-kernel
  Cc: Barry Song, Geert Uytterhoeven, Julia Lawall,
	Krzysztof Kozlowski, Linus Walleij, Ludovic Desroches,
	Patrice Chotard, Rob Herring, LKML, kernel-janitors

>> Are you looking for a limitation of such source code search patterns?
> 
> Exactly.

Would you like to explain your view a bit more?

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
  2017-10-30 19:15 ` Geert Uytterhoeven
  2017-10-30 19:32   ` SF Markus Elfring
@ 2017-11-01 10:33   ` Dan Carpenter
  1 sibling, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2017-11-01 10:33 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: SF Markus Elfring, linux-gpio, linux-arm-kernel, Barry Song,
	Geert Uytterhoeven, Julia Lawall, Krzysztof Kozlowski,
	Linus Walleij, Ludovic Desroches, Patrice Chotard, Rob Herring,
	LKML, kernel-janitors

Really, the of_node_put() is connected to the loop and not the function
so the original code is the right way to do it.  Otherwise if we added
more error handling to the function then normal kernel error handling
wouldn't work naturally.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-01 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-30 18:36 [PATCH] pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map() SF Markus Elfring
2017-10-30 19:15 ` Geert Uytterhoeven
2017-10-30 19:32   ` SF Markus Elfring
2017-10-30 19:34     ` Geert Uytterhoeven
2017-10-30 19:41       ` SF Markus Elfring
2017-11-01 10:33   ` [PATCH] " Dan Carpenter

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).