Skip to content

Commit ba35b9a

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: lp50xx: 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 '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-10-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 6e2d1d8 commit ba35b9a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

drivers/leds/leds-lp50xx.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ static int lp50xx_probe_leds(struct fwnode_handle *child, struct lp50xx *priv,
434434

435435
static int lp50xx_probe_dt(struct lp50xx *priv)
436436
{
437-
struct fwnode_handle *child = NULL;
438437
struct fwnode_handle *led_node = NULL;
439438
struct led_init_data init_data = {};
440439
struct led_classdev *led_cdev;
@@ -454,17 +453,17 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
454453
if (IS_ERR(priv->regulator))
455454
priv->regulator = NULL;
456455

457-
device_for_each_child_node(priv->dev, child) {
456+
device_for_each_child_node_scoped(priv->dev, child) {
458457
led = &priv->leds[i];
459458
ret = fwnode_property_count_u32(child, "reg");
460459
if (ret < 0) {
461460
dev_err(priv->dev, "reg property is invalid\n");
462-
goto child_out;
461+
return ret;
463462
}
464463

465464
ret = lp50xx_probe_leds(child, priv, led, ret);
466465
if (ret)
467-
goto child_out;
466+
return ret;
468467

469468
init_data.fwnode = child;
470469
num_colors = 0;
@@ -475,18 +474,16 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
475474
*/
476475
mc_led_info = devm_kcalloc(priv->dev, LP50XX_LEDS_PER_MODULE,
477476
sizeof(*mc_led_info), GFP_KERNEL);
478-
if (!mc_led_info) {
479-
ret = -ENOMEM;
480-
goto child_out;
481-
}
477+
if (!mc_led_info)
478+
return -ENOMEM;
482479

483480
fwnode_for_each_child_node(child, led_node) {
484481
ret = fwnode_property_read_u32(led_node, "color",
485482
&color_id);
486483
if (ret) {
487484
fwnode_handle_put(led_node);
488485
dev_err(priv->dev, "Cannot read color\n");
489-
goto child_out;
486+
return ret;
490487
}
491488

492489
mc_led_info[num_colors].color_index = color_id;
@@ -504,16 +501,12 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
504501
&init_data);
505502
if (ret) {
506503
dev_err(priv->dev, "led register err: %d\n", ret);
507-
goto child_out;
504+
return ret;
508505
}
509506
i++;
510507
}
511508

512509
return 0;
513-
514-
child_out:
515-
fwnode_handle_put(child);
516-
return ret;
517510
}
518511

519512
static int lp50xx_probe(struct i2c_client *client)

0 commit comments

Comments
 (0)