linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Zhang <zhangpeng362@huawei.com>
To: <pavel@ucw.cz>, <andersson@kernel.org>, <swboyd@chromium.org>,
	<quic_c_skakit@quicinc.com>, <marijn.suijten@somainline.org>
Cc: <linux-leds@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	ZhangPeng <zhangpeng362@huawei.com>
Subject: [PATCH] leds: call of_node_put() when breaking out of for_each_available_child_of_node()
Date: Tue, 22 Nov 2022 06:50:02 +0000	[thread overview]
Message-ID: <20221122065002.2327772-1-zhangpeng362@huawei.com> (raw)

From: ZhangPeng <zhangpeng362@huawei.com>

Since for_each_available_child_of_node() will increase the refcount of
node, we need to call of_node_put() manually when breaking out of the
iteration.

Fixes: 24e2d05d1b68 ("leds: Add driver for Qualcomm LPG")
Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
 drivers/leds/rgb/leds-qcom-lpg.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c
index 02f51cc61837..8075115cef58 100644
--- a/drivers/leds/rgb/leds-qcom-lpg.c
+++ b/drivers/leds/rgb/leds-qcom-lpg.c
@@ -1084,7 +1084,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
 	ret = of_property_read_u32(np, "color", &color);
 	if (ret < 0 && ret != -EINVAL) {
 		dev_err(lpg->dev, "failed to parse \"color\" of %pOF\n", np);
-		return ret;
+		goto err_put_np_node;
 	}
 
 	if (color == LED_COLOR_ID_RGB)
@@ -1093,21 +1093,25 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
 		num_channels = 1;
 
 	led = devm_kzalloc(lpg->dev, struct_size(led, channels, num_channels), GFP_KERNEL);
-	if (!led)
-		return -ENOMEM;
+	if (!led) {
+		ret = -ENOMEM
+		goto err_put_np_node;
+	}
 
 	led->lpg = lpg;
 	led->num_channels = num_channels;
 
 	if (color == LED_COLOR_ID_RGB) {
 		info = devm_kcalloc(lpg->dev, num_channels, sizeof(*info), GFP_KERNEL);
-		if (!info)
-			return -ENOMEM;
+		if (!info) {
+			ret = -ENOMEM
+			goto err_put_np_node;
+		}
 		i = 0;
 		for_each_available_child_of_node(np, child) {
 			ret = lpg_parse_channel(lpg, child, &led->channels[i]);
 			if (ret < 0)
-				return ret;
+				goto err_put_child_node;
 
 			info[i].color_index = led->channels[i]->color;
 			info[i].intensity = 0;
@@ -1129,7 +1133,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
 	} else {
 		ret = lpg_parse_channel(lpg, np, &led->channels[0]);
 		if (ret < 0)
-			return ret;
+			goto err_put_np_node;
 
 		cdev = &led->cdev;
 		cdev->brightness_set = lpg_brightness_single_set;
@@ -1161,7 +1165,15 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
 		ret = devm_led_classdev_register_ext(lpg->dev, &led->cdev, &init_data);
 	if (ret)
 		dev_err(lpg->dev, "unable to register %s\n", cdev->name);
+	else
+		return ret;
+
+err_put_np_node:
+	of_node_put(np);
+	return ret;
 
+err_put_child_node:
+	of_node_put(child);
 	return ret;
 }
 
-- 
2.25.1


                 reply	other threads:[~2022-11-22  6:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221122065002.2327772-1-zhangpeng362@huawei.com \
    --to=zhangpeng362@huawei.com \
    --cc=andersson@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=marijn.suijten@somainline.org \
    --cc=pavel@ucw.cz \
    --cc=quic_c_skakit@quicinc.com \
    --cc=swboyd@chromium.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).