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

leds: pwm: 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 paths.

This also prevents possible memory leaks if new error paths are added
without the required call to fwnode_handle_put().

After switching to the scoped variant, there is no longer need for a
jump to 'err_child_out', as an immediate return is possible.

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-14-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Javier Carrasco and committed by
Lee Jones
e3456071 dea90acb

+4 -11
+4 -11
drivers/leds/leds-pwm.c
··· 140 140 141 141 static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv) 142 142 { 143 - struct fwnode_handle *fwnode; 144 143 struct led_pwm led; 145 144 int ret; 146 145 147 - device_for_each_child_node(dev, fwnode) { 146 + device_for_each_child_node_scoped(dev, fwnode) { 148 147 memset(&led, 0, sizeof(led)); 149 148 150 149 ret = fwnode_property_read_string(fwnode, "label", &led.name); 151 150 if (ret && is_of_node(fwnode)) 152 151 led.name = to_of_node(fwnode)->name; 153 152 154 - if (!led.name) { 155 - ret = -EINVAL; 156 - goto err_child_out; 157 - } 153 + if (!led.name) 154 + return -EINVAL; 158 155 159 156 led.active_low = fwnode_property_read_bool(fwnode, 160 157 "active-low"); ··· 162 165 163 166 ret = led_pwm_add(dev, priv, &led, fwnode); 164 167 if (ret) 165 - goto err_child_out; 168 + return ret; 166 169 } 167 170 168 171 return 0; 169 - 170 - err_child_out: 171 - fwnode_handle_put(fwnode); 172 - return ret; 173 172 } 174 173 175 174 static int led_pwm_probe(struct platform_device *pdev)