pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
Subsystems (3)
PATCH 1/1 pinctrl: sirf: Use common error handling code in sirfsoc_dt_node_to_map()
From: Markus Elfring <[email protected]>
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.
--- drivers/pinctrl/sirf/pinctrl-sirf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pinctrl/sirf/pinctrl-sirf.c +8 -8
@@ -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,
Signature · 1 line
2.14.3
Hi Markus,
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 30 Oct 2017 19:26:56 +0100Add 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?
Quoted 4 lines
Signed-off-by Markus Elfring <[email protected]>--- 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.
Quoted 26 lines
drivers/pinctrl/sirf/pinctrl-sirf.c +4
-8@@ -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; }
drivers/pinctrl/sirf/pinctrl-sirf.c static int sirfsoc_dt_node_to_map(struct pinctrl_dev *pctldev, · line 128
Quoted 8 lines
drivers/pinctrl/sirf/pinctrl-sirf.c +4
-0@@ -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 -- [email protected]
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
Quoted 6 lines
Quoted 4 lines
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
Quoted 8 lines · SF Markus Elfring
Quoted 6 lines
Quoted 4 lines
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 -- [email protected]
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
Quoted 3 lines
Quoted 1 line
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
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