Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

backlight: lm3509_bl: Fix early returns in for_each_child_of_node()

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 <lkp@intel.com>
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>
Link: https://lore.kernel.org/r/20240624-lm3509_bl_scoped-v1-1-ceba9df38f23@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Javier Carrasco and committed by
Lee Jones
b337cc3c bfd35877

+1 -2
+1 -2
drivers/video/backlight/lm3509_bl.c
··· 157 157 static int lm3509_parse_dt_node(struct device *dev, 158 158 struct lm3509_bl_led_data *led_data) 159 159 { 160 - struct device_node *child; 161 160 int seen_led_sources = 0; 162 161 163 - for_each_child_of_node(dev->of_node, child) { 162 + for_each_child_of_node_scoped(dev->of_node, child) { 164 163 struct lm3509_bl_led_data *ld; 165 164 int ret; 166 165 u32 reg;