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

leds: flash: mt6370: 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().

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

authored by

Javier Carrasco and committed by
Lee Jones
19d1cc76 73b03b27

+3 -8
+3 -8
drivers/leds/flash/leds-mt6370-flash.c
··· 509 509 { 510 510 struct device *dev = &pdev->dev; 511 511 struct mt6370_priv *priv; 512 - struct fwnode_handle *child; 513 512 size_t count; 514 513 int i = 0, ret; 515 514 ··· 528 529 if (!priv->regmap) 529 530 return dev_err_probe(dev, -ENODEV, "Failed to get parent regmap\n"); 530 531 531 - device_for_each_child_node(dev, child) { 532 + device_for_each_child_node_scoped(dev, child) { 532 533 struct mt6370_led *led = priv->leds + i; 533 534 534 535 led->priv = priv; 535 536 536 537 ret = mt6370_init_flash_properties(dev, led, child); 537 - if (ret) { 538 - fwnode_handle_put(child); 538 + if (ret) 539 539 return ret; 540 - } 541 540 542 541 ret = mt6370_led_register(dev, led, child); 543 - if (ret) { 544 - fwnode_handle_put(child); 542 + if (ret) 545 543 return ret; 546 - } 547 544 548 545 i++; 549 546 }