Skip to content

Commit e345607

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-14-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent dea90ac commit e345607

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

drivers/leds/leds-pwm.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,18 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
140140

141141
static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
142142
{
143-
struct fwnode_handle *fwnode;
144143
struct led_pwm led;
145144
int ret;
146145

147-
device_for_each_child_node(dev, fwnode) {
146+
device_for_each_child_node_scoped(dev, fwnode) {
148147
memset(&led, 0, sizeof(led));
149148

150149
ret = fwnode_property_read_string(fwnode, "label", &led.name);
151150
if (ret && is_of_node(fwnode))
152151
led.name = to_of_node(fwnode)->name;
153152

154-
if (!led.name) {
155-
ret = -EINVAL;
156-
goto err_child_out;
157-
}
153+
if (!led.name)
154+
return -EINVAL;
158155

159156
led.active_low = fwnode_property_read_bool(fwnode,
160157
"active-low");
@@ -165,14 +162,10 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
165162

166163
ret = led_pwm_add(dev, priv, &led, fwnode);
167164
if (ret)
168-
goto err_child_out;
165+
return ret;
169166
}
170167

171168
return 0;
172-
173-
err_child_out:
174-
fwnode_handle_put(fwnode);
175-
return ret;
176169
}
177170

178171
static int led_pwm_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)