Skip to content

Commit 01728d0

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: tca6507: Switch to device_for_each_child_node_scoped()
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 path. This also prevents possible memory leaks if new error paths are added without the required call to fwnode_handle_put(). Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-16-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 8cf103d commit 01728d0

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

drivers/leds/leds-tca6507.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@ static struct tca6507_platform_data *
658658
tca6507_led_dt_init(struct device *dev)
659659
{
660660
struct tca6507_platform_data *pdata;
661-
struct fwnode_handle *child;
662661
struct led_info *tca_leds;
663662
int count;
664663

@@ -671,7 +670,7 @@ tca6507_led_dt_init(struct device *dev)
671670
if (!tca_leds)
672671
return ERR_PTR(-ENOMEM);
673672

674-
device_for_each_child_node(dev, child) {
673+
device_for_each_child_node_scoped(dev, child) {
675674
struct led_info led;
676675
u32 reg;
677676
int ret;
@@ -688,10 +687,8 @@ tca6507_led_dt_init(struct device *dev)
688687
led.flags |= TCA6507_MAKE_GPIO;
689688

690689
ret = fwnode_property_read_u32(child, "reg", &reg);
691-
if (ret || reg >= NUM_LEDS) {
692-
fwnode_handle_put(child);
690+
if (ret || reg >= NUM_LEDS)
693691
return ERR_PTR(ret ? : -EINVAL);
694-
}
695692

696693
tca_leds[reg] = led;
697694
}

0 commit comments

Comments
 (0)