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

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 <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-16-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Javier Carrasco and committed by
Lee Jones
01728d04 8cf103de

+2 -5
+2 -5
drivers/leds/leds-tca6507.c
··· 658 658 tca6507_led_dt_init(struct device *dev) 659 659 { 660 660 struct tca6507_platform_data *pdata; 661 - struct fwnode_handle *child; 662 661 struct led_info *tca_leds; 663 662 int count; 664 663 ··· 670 671 if (!tca_leds) 671 672 return ERR_PTR(-ENOMEM); 672 673 673 - device_for_each_child_node(dev, child) { 674 + device_for_each_child_node_scoped(dev, child) { 674 675 struct led_info led; 675 676 u32 reg; 676 677 int ret; ··· 687 688 led.flags |= TCA6507_MAKE_GPIO; 688 689 689 690 ret = fwnode_property_read_u32(child, "reg", &reg); 690 - if (ret || reg >= NUM_LEDS) { 691 - fwnode_handle_put(child); 691 + if (ret || reg >= NUM_LEDS) 692 692 return ERR_PTR(ret ? : -EINVAL); 693 - } 694 693 695 694 tca_leds[reg] = led; 696 695 }