linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: ncp5623: Use common error handling code in ncp5623_probe()
@ 2024-06-05 14:30 Markus Elfring
  2024-06-13 14:47 ` Lee Jones
  2024-06-13 16:05 ` (subset) " Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2024-06-05 14:30 UTC (permalink / raw)
  To: linux-leds, Abdel Alkuor, Lee Jones, Pavel Machek; +Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 5 Jun 2024 16:19:26 +0200

Add a label so that a bit of exception handling can be better reused
at the end of this function implementation.

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

diff --git a/drivers/leds/rgb/leds-ncp5623.c b/drivers/leds/rgb/leds-ncp5623.c
index 2be4ff918516..f18156683375 100644
--- a/drivers/leds/rgb/leds-ncp5623.c
+++ b/drivers/leds/rgb/leds-ncp5623.c
@@ -183,16 +183,12 @@ static int ncp5623_probe(struct i2c_client *client)

 	fwnode_for_each_available_child_node(mc_node, led_node) {
 		ret = fwnode_property_read_u32(led_node, "color", &color_index);
-		if (ret) {
-			fwnode_handle_put(led_node);
-			goto release_mc_node;
-		}
+		if (ret)
+			goto release_led_node;

 		ret = fwnode_property_read_u32(led_node, "reg", &reg);
-		if (ret) {
-			fwnode_handle_put(led_node);
-			goto release_mc_node;
-		}
+		if (ret)
+			goto release_led_node;

 		subled_info[ncp->mc_dev.num_colors].channel = reg;
 		subled_info[ncp->mc_dev.num_colors++].color_index = color_index;
@@ -223,6 +219,10 @@ static int ncp5623_probe(struct i2c_client *client)
 	fwnode_handle_put(mc_node);

 	return ret;
+
+release_led_node:
+	fwnode_handle_put(led_node);
+	goto release_mc_node;
 }

 static void ncp5623_remove(struct i2c_client *client)
--
2.45.1


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

* Re: [PATCH] leds: ncp5623: Use common error handling code in ncp5623_probe()
  2024-06-05 14:30 [PATCH] leds: ncp5623: Use common error handling code in ncp5623_probe() Markus Elfring
@ 2024-06-13 14:47 ` Lee Jones
  2024-06-13 16:05 ` (subset) " Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2024-06-13 14:47 UTC (permalink / raw)
  To: Markus Elfring; +Cc: linux-leds, Abdel Alkuor, Pavel Machek, LKML

On Wed, 05 Jun 2024, Markus Elfring wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 5 Jun 2024 16:19:26 +0200
> 
> Add a label so that a bit of exception handling can be better reused
> at the end of this function implementation.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/leds/rgb/leds-ncp5623.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/leds/rgb/leds-ncp5623.c b/drivers/leds/rgb/leds-ncp5623.c
> index 2be4ff918516..f18156683375 100644
> --- a/drivers/leds/rgb/leds-ncp5623.c
> +++ b/drivers/leds/rgb/leds-ncp5623.c
> @@ -183,16 +183,12 @@ static int ncp5623_probe(struct i2c_client *client)
> 
>  	fwnode_for_each_available_child_node(mc_node, led_node) {
>  		ret = fwnode_property_read_u32(led_node, "color", &color_index);
> -		if (ret) {
> -			fwnode_handle_put(led_node);
> -			goto release_mc_node;
> -		}
> +		if (ret)
> +			goto release_led_node;
> 
>  		ret = fwnode_property_read_u32(led_node, "reg", &reg);
> -		if (ret) {
> -			fwnode_handle_put(led_node);
> -			goto release_mc_node;
> -		}
> +		if (ret)
> +			goto release_led_node;
> 
>  		subled_info[ncp->mc_dev.num_colors].channel = reg;
>  		subled_info[ncp->mc_dev.num_colors++].color_index = color_index;
> @@ -223,6 +219,10 @@ static int ncp5623_probe(struct i2c_client *client)
>  	fwnode_handle_put(mc_node);
> 
>  	return ret;
> +
> +release_led_node:
> +	fwnode_handle_put(led_node);
> +	goto release_mc_node;

No, we're not bouncing around the function like that.

Only use gotos to skip _down_ to error handling code please.

>  }
> 
>  static void ncp5623_remove(struct i2c_client *client)
> --
> 2.45.1
> 

-- 
Lee Jones [李琼斯]

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

* Re: (subset) [PATCH] leds: ncp5623: Use common error handling code in ncp5623_probe()
  2024-06-05 14:30 [PATCH] leds: ncp5623: Use common error handling code in ncp5623_probe() Markus Elfring
  2024-06-13 14:47 ` Lee Jones
@ 2024-06-13 16:05 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2024-06-13 16:05 UTC (permalink / raw)
  To: linux-leds, Abdel Alkuor, Pavel Machek, Markus Elfring; +Cc: LKML

On Wed, 05 Jun 2024 16:30:30 +0200, Markus Elfring wrote:
> Add a label so that a bit of exception handling can be better reused
> at the end of this function implementation.
> 
> 

Applied, thanks!

[1/1] leds: ncp5623: Use common error handling code in ncp5623_probe()
      commit: b234df8016fc73468dfff2ea91c5b150bbe6f692

--
Lee Jones [李琼斯]


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

end of thread, other threads:[~2024-06-13 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-05 14:30 [PATCH] leds: ncp5623: Use common error handling code in ncp5623_probe() Markus Elfring
2024-06-13 14:47 ` Lee Jones
2024-06-13 16:05 ` (subset) " Lee Jones

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