Skip to content

Commit 9e445e2

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: el15203000: 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-6-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 65135e2 commit 9e445e2

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

drivers/leds/leds-el15203000.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,20 @@ static int el15203000_pattern_clear(struct led_classdev *ldev)
237237
static int el15203000_probe_dt(struct el15203000 *priv)
238238
{
239239
struct el15203000_led *led = priv->leds;
240-
struct fwnode_handle *child;
241240
int ret;
242241

243-
device_for_each_child_node(priv->dev, child) {
242+
device_for_each_child_node_scoped(priv->dev, child) {
244243
struct led_init_data init_data = {};
245244

246245
ret = fwnode_property_read_u32(child, "reg", &led->reg);
247246
if (ret) {
248247
dev_err(priv->dev, "LED without ID number");
249-
goto err_child_out;
248+
return ret;
250249
}
251250

252251
if (led->reg > U8_MAX) {
253252
dev_err(priv->dev, "LED value %d is invalid", led->reg);
254-
ret = -EINVAL;
255-
goto err_child_out;
253+
return -EINVAL;
256254
}
257255

258256
led->priv = priv;
@@ -274,17 +272,13 @@ static int el15203000_probe_dt(struct el15203000 *priv)
274272
dev_err(priv->dev,
275273
"failed to register LED device %s, err %d",
276274
led->ldev.name, ret);
277-
goto err_child_out;
275+
return ret;
278276
}
279277

280278
led++;
281279
}
282280

283281
return 0;
284-
285-
err_child_out:
286-
fwnode_handle_put(child);
287-
return ret;
288282
}
289283

290284
static int el15203000_probe(struct spi_device *spi)

0 commit comments

Comments
 (0)