linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	 Gene Chen <gene_chen@richtek.com>,
	 Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	 Bartosz Golaszewski <brgl@bgdev.pl>,
	Chen-Yu Tsai <wens@csie.org>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Samuel Holland <samuel@sholland.org>,
	 Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,  linux-sunxi@lists.linux.dev,
	 Javier Carrasco <javier.carrasco.cruz@gmail.com>
Subject: [PATCH 15/18] leds: sun50i-a100: switch to device_for_each_child_node_scoped()
Date: Fri, 27 Sep 2024 01:21:06 +0200	[thread overview]
Message-ID: <20240927-leds_device_for_each_child_node_scoped-v1-15-95c0614b38c8@gmail.com> (raw)
In-Reply-To: <20240927-leds_device_for_each_child_node_scoped-v1-0-95c0614b38c8@gmail.com>

Switch to device_for_each_child_node_scoped() to simplify the code by
removing the need for calls to fwnode_handle_put() in the error paths.

This also prevents possible memory leaks if new error paths are added
without the required call to fwnode_handle_put().

The error handling after 'err_put_child' has been moved to the only goto
that jumps to it (second device_for_each_child_node()), and the call to
fwnode_handle_put() has been removed accordingly.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/leds/leds-sun50i-a100.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/drivers/leds/leds-sun50i-a100.c b/drivers/leds/leds-sun50i-a100.c
index 4c468d487486..03f1b6424692 100644
--- a/drivers/leds/leds-sun50i-a100.c
+++ b/drivers/leds/leds-sun50i-a100.c
@@ -392,7 +392,6 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
 	struct sun50i_a100_ledc_led *led;
 	struct device *dev = &pdev->dev;
 	struct sun50i_a100_ledc *priv;
-	struct fwnode_handle *child;
 	struct resource *mem;
 	u32 max_addr = 0;
 	u32 num_leds = 0;
@@ -402,21 +401,17 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
 	 * The maximum LED address must be known in sun50i_a100_ledc_resume() before
 	 * class device registration, so parse and validate the subnodes up front.
 	 */
-	device_for_each_child_node(dev, child) {
+	device_for_each_child_node_scoped(dev, child) {
 		u32 addr, color;
 
 		ret = fwnode_property_read_u32(child, "reg", &addr);
-		if (ret || addr >= LEDC_MAX_LEDS) {
-			fwnode_handle_put(child);
+		if (ret || addr >= LEDC_MAX_LEDS)
 			return dev_err_probe(dev, -EINVAL, "'reg' must be between 0 and %d\n",
 					     LEDC_MAX_LEDS - 1);
-		}
 
 		ret = fwnode_property_read_u32(child, "color", &color);
-		if (ret || color != LED_COLOR_ID_RGB) {
-			fwnode_handle_put(child);
+		if (ret || color != LED_COLOR_ID_RGB)
 			return dev_err_probe(dev, -EINVAL, "'color' must be LED_COLOR_ID_RGB\n");
-		}
 
 		max_addr = max(max_addr, addr);
 		num_leds++;
@@ -502,7 +497,7 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
 		return ret;
 
 	led = priv->leds;
-	device_for_each_child_node(dev, child) {
+	device_for_each_child_node_scoped(dev, child) {
 		struct led_classdev *cdev;
 
 		/* The node was already validated above. */
@@ -527,7 +522,11 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
 		ret = led_classdev_multicolor_register_ext(dev, &led->mc_cdev, &init_data);
 		if (ret) {
 			dev_err_probe(dev, ret, "Failed to register multicolor LED %u", led->addr);
-			goto err_put_child;
+			while (led-- > priv->leds)
+				led_classdev_multicolor_unregister(&led->mc_cdev);
+			sun50i_a100_ledc_suspend(&pdev->dev);
+
+			return ret;
 		}
 
 		led++;
@@ -536,14 +535,6 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
 	dev_info(dev, "Registered %u LEDs\n", num_leds);
 
 	return 0;
-
-err_put_child:
-	fwnode_handle_put(child);
-	while (led-- > priv->leds)
-		led_classdev_multicolor_unregister(&led->mc_cdev);
-	sun50i_a100_ledc_suspend(&pdev->dev);
-
-	return ret;
 }
 
 static void sun50i_a100_ledc_remove(struct platform_device *pdev)

-- 
2.43.0



  parent reply	other threads:[~2024-09-26 23:41 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26 23:20 [PATCH 00/18] leds: switch to device_for_each_child_node_scoped() Javier Carrasco
2024-09-26 23:20 ` [PATCH 01/18] leds: flash: mt6360: fix device_for_each_child_node() refcounting in error paths Javier Carrasco
2024-09-26 23:20 ` [PATCH 02/18] leds: flash: mt6370: switch to device_for_each_child_node_scoped() Javier Carrasco
2024-09-26 23:20 ` [PATCH 03/18] leds: flash: leds-qcom-flash: " Javier Carrasco
2024-09-26 23:20 ` [PATCH 04/18] leds: aw200xx: " Javier Carrasco
2024-09-26 23:20 ` [PATCH 05/18] leds: cr0014114: " Javier Carrasco
2024-11-23 19:31   ` Andy Shevchenko
2024-09-26 23:20 ` [PATCH 06/18] leds: el15203000: " Javier Carrasco
2024-11-23 19:34   ` Andy Shevchenko
2024-09-26 23:20 ` [PATCH 07/18] leds: gpio: " Javier Carrasco
2024-11-23 19:35   ` Andy Shevchenko
2024-09-26 23:20 ` [PATCH 08/18] leds: lm3532: " Javier Carrasco
2024-11-23 19:37   ` Andy Shevchenko
2024-09-26 23:21 ` [PATCH 09/18] leds: lm3697: " Javier Carrasco
2024-11-23 19:37   ` Andy Shevchenko
2024-09-26 23:21 ` [PATCH 10/18] leds: lp50xx: " Javier Carrasco
2024-09-26 23:21 ` [PATCH 11/18] leds: max77650: " Javier Carrasco
2024-09-27  6:36   ` Bartosz Golaszewski
2024-11-23 19:47   ` Andy Shevchenko
2024-09-26 23:21 ` [PATCH 12/18] leds: ns2: " Javier Carrasco
2024-09-26 23:21 ` [PATCH 13/18] leds: pca963x: " Javier Carrasco
2024-11-23 19:45   ` Andy Shevchenko
2024-09-26 23:21 ` [PATCH 14/18] leds: pwm: " Javier Carrasco
2024-09-26 23:21 ` Javier Carrasco [this message]
2024-11-23 19:41   ` [PATCH 15/18] leds: sun50i-a100: " Andy Shevchenko
2024-09-26 23:21 ` [PATCH 16/18] leds: tca6507: " Javier Carrasco
2024-11-23 19:40   ` Andy Shevchenko
2024-09-26 23:21 ` [PATCH 17/18] leds: rgb: ktd202x: " Javier Carrasco
2024-09-26 23:21 ` [PATCH 18/18] leds: rgb: mt6370: " Javier Carrasco
2024-10-09 14:20 ` [PATCH 00/18] leds: " Lee Jones
2024-11-23 19:29 ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240927-leds_device_for_each_child_node_scoped-v1-15-95c0614b38c8@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=brgl@bgdev.pl \
    --cc=gene_chen@richtek.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=matthias.bgg@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).