Skip to content

Commit 5b5d936

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: ns2: 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-12-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 4ab3ae4 commit 5b5d936

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

drivers/leds/leds-ns2.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ static int ns2_led_register(struct device *dev, struct fwnode_handle *node,
238238
static int ns2_led_probe(struct platform_device *pdev)
239239
{
240240
struct device *dev = &pdev->dev;
241-
struct fwnode_handle *child;
242241
struct ns2_led *leds;
243242
int count;
244243
int ret;
@@ -251,12 +250,10 @@ static int ns2_led_probe(struct platform_device *pdev)
251250
if (!leds)
252251
return -ENOMEM;
253252

254-
device_for_each_child_node(dev, child) {
253+
device_for_each_child_node_scoped(dev, child) {
255254
ret = ns2_led_register(dev, child, leds++);
256-
if (ret) {
257-
fwnode_handle_put(child);
255+
if (ret)
258256
return ret;
259-
}
260257
}
261258

262259
return 0;

0 commit comments

Comments
 (0)