[PATCH] backlight: lm3509_bl: Fix early returns in for_each_child_of_node()

Subsystems: backlight class/subsystem, framebuffer layer, the rest

STALE807d LANDED

Landed in mainline as b337cc3ce475 on 2024-06-26.

2 messages, 2 authors, 2024-06-26 · open the first message on its own page

[PATCH] backlight: lm3509_bl: Fix early returns in for_each_child_of_node()

From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Date: 2024-06-24 15:30:53

The for_each_child_of_node() macro automatically decrements the child
refcount at the end of every iteration. On early exits, of_node_put()
must be used to manually decrement the refcount and avoid memory leaks.

The scoped version of the macro accounts for such early breaks, fixing
the early exits without the need for explicit calls to of_node_put().

Reported-by: kernel test robot <redacted>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202406172314.2vVgelaS-lkp@intel.com/
Fixes: b72755f5b577 ("backlight: Add new lm3509 backlight driver")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/video/backlight/lm3509_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/video/backlight/lm3509_bl.c b/drivers/video/backlight/lm3509_bl.c
index c93cdedff5ad..7a36f5c08640 100644
--- a/drivers/video/backlight/lm3509_bl.c
+++ b/drivers/video/backlight/lm3509_bl.c
@@ -157,10 +157,9 @@ static int lm3509_parse_led_sources(struct device_node *node,
 static int lm3509_parse_dt_node(struct device *dev,
 				struct lm3509_bl_led_data *led_data)
 {
-	struct device_node *child;
 	int seen_led_sources = 0;
 
-	for_each_child_of_node(dev->of_node, child) {
+	for_each_child_of_node_scoped(dev->of_node, child) {
 		struct lm3509_bl_led_data *ld;
 		int ret;
 		u32 reg;
---
base-commit: f76698bd9a8ca01d3581236082d786e9a6b72bb7
change-id: 20240624-lm3509_bl_scoped-75983f702aed

Best regards,
-- 
Javier Carrasco [off-list ref]

Re: (subset) [PATCH] backlight: lm3509_bl: Fix early returns in for_each_child_of_node()

From: Lee Jones <lee@kernel.org>
Date: 2024-06-26 15:50:09

On Mon, 24 Jun 2024 17:30:50 +0200, Javier Carrasco wrote:
The for_each_child_of_node() macro automatically decrements the child
refcount at the end of every iteration. On early exits, of_node_put()
must be used to manually decrement the refcount and avoid memory leaks.

The scoped version of the macro accounts for such early breaks, fixing
the early exits without the need for explicit calls to of_node_put().

[...]
Applied, thanks!

[1/1] backlight: lm3509_bl: Fix early returns in for_each_child_of_node()
      commit: b337cc3ce47549528fc3ee0b8c7ebd33348a3126

--
Lee Jones [李琼斯]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help