Skip to content

Commit 8cf103d

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: sun50i-a100: 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(). The error handling after 'err_put_child' has been moved to the only goto that jumps to it (second device_for_each_child_node()), and the call to fwnode_handle_put() has been removed accordingly. Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-15-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent e345607 commit 8cf103d

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

drivers/leds/leds-sun50i-a100.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
392392
struct sun50i_a100_ledc_led *led;
393393
struct device *dev = &pdev->dev;
394394
struct sun50i_a100_ledc *priv;
395-
struct fwnode_handle *child;
396395
struct resource *mem;
397396
u32 max_addr = 0;
398397
u32 num_leds = 0;
@@ -402,21 +401,17 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
402401
* The maximum LED address must be known in sun50i_a100_ledc_resume() before
403402
* class device registration, so parse and validate the subnodes up front.
404403
*/
405-
device_for_each_child_node(dev, child) {
404+
device_for_each_child_node_scoped(dev, child) {
406405
u32 addr, color;
407406

408407
ret = fwnode_property_read_u32(child, "reg", &addr);
409-
if (ret || addr >= LEDC_MAX_LEDS) {
410-
fwnode_handle_put(child);
408+
if (ret || addr >= LEDC_MAX_LEDS)
411409
return dev_err_probe(dev, -EINVAL, "'reg' must be between 0 and %d\n",
412410
LEDC_MAX_LEDS - 1);
413-
}
414411

415412
ret = fwnode_property_read_u32(child, "color", &color);
416-
if (ret || color != LED_COLOR_ID_RGB) {
417-
fwnode_handle_put(child);
413+
if (ret || color != LED_COLOR_ID_RGB)
418414
return dev_err_probe(dev, -EINVAL, "'color' must be LED_COLOR_ID_RGB\n");
419-
}
420415

421416
max_addr = max(max_addr, addr);
422417
num_leds++;
@@ -502,7 +497,7 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
502497
return ret;
503498

504499
led = priv->leds;
505-
device_for_each_child_node(dev, child) {
500+
device_for_each_child_node_scoped(dev, child) {
506501
struct led_classdev *cdev;
507502

508503
/* The node was already validated above. */
@@ -527,7 +522,11 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
527522
ret = led_classdev_multicolor_register_ext(dev, &led->mc_cdev, &init_data);
528523
if (ret) {
529524
dev_err_probe(dev, ret, "Failed to register multicolor LED %u", led->addr);
530-
goto err_put_child;
525+
while (led-- > priv->leds)
526+
led_classdev_multicolor_unregister(&led->mc_cdev);
527+
sun50i_a100_ledc_suspend(&pdev->dev);
528+
529+
return ret;
531530
}
532531

533532
led++;
@@ -536,14 +535,6 @@ static int sun50i_a100_ledc_probe(struct platform_device *pdev)
536535
dev_info(dev, "Registered %u LEDs\n", num_leds);
537536

538537
return 0;
539-
540-
err_put_child:
541-
fwnode_handle_put(child);
542-
while (led-- > priv->leds)
543-
led_classdev_multicolor_unregister(&led->mc_cdev);
544-
sun50i_a100_ledc_suspend(&pdev->dev);
545-
546-
return ret;
547538
}
548539

549540
static void sun50i_a100_ledc_remove(struct platform_device *pdev)

0 commit comments

Comments
 (0)