linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lu Hongfei <luhongfei@vivo.com>
To: "Pavel Machek" <pavel@ucw.cz>, "Lee Jones" <lee@kernel.org>,
	"Anjelique Melendez" <quic_amelende@quicinc.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
	"Lu Hongfei" <11117923@bbktel.com>,
	linux-leds@vger.kernel.org (open list:LED SUBSYSTEM),
	linux-kernel@vger.kernel.org (open list)
Cc: opensource.kernel@vivo.com, luhongfei@vivo.com
Subject: [PATCH] led: qcom-lpg: Fix resource leaks in for_each_available_child_of_node() loops
Date: Thu, 25 May 2023 19:17:03 +0800	[thread overview]
Message-ID: <20230525111705.3055-1-luhongfei@vivo.com> (raw)

for_each_available_child_of_node in lpg_probe and lpg_add_led need
to execute of_node_put before return. this patch could fix this bug.

Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
---
 drivers/leds/rgb/leds-qcom-lpg.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 drivers/leds/rgb/leds-qcom-lpg.c

diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c
index 55a037234df1..0e8ff36c4bf7
--- a/drivers/leds/rgb/leds-qcom-lpg.c
+++ b/drivers/leds/rgb/leds-qcom-lpg.c
@@ -1173,8 +1173,10 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
 		i = 0;
 		for_each_available_child_of_node(np, child) {
 			ret = lpg_parse_channel(lpg, child, &led->channels[i]);
-			if (ret < 0)
+			if (ret < 0) {
+				of_node_put(child);
 				return ret;
+			}
 
 			info[i].color_index = led->channels[i]->color;
 			info[i].intensity = 0;
@@ -1352,8 +1354,10 @@ static int lpg_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(pdev->dev.of_node, np) {
 		ret = lpg_add_led(lpg, np);
-		if (ret)
+		if (ret) {
+			of_node_put(np);
 			return ret;
+		}
 	}
 
 	for (i = 0; i < lpg->num_channels; i++)
-- 
2.39.0


             reply	other threads:[~2023-05-25 11:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 11:17 Lu Hongfei [this message]
2023-05-25 12:02 ` [PATCH] led: qcom-lpg: Fix resource leaks in for_each_available_child_of_node() loops Lee Jones

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=20230525111705.3055-1-luhongfei@vivo.com \
    --to=luhongfei@vivo.com \
    --cc=11117923@bbktel.com \
    --cc=conor.dooley@microchip.com \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=opensource.kernel@vivo.com \
    --cc=pavel@ucw.cz \
    --cc=quic_amelende@quicinc.com \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).