Skip to content

Commit 7bd4b92

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: lm3532: 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-8-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 42b4967 commit 7bd4b92

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

drivers/leds/leds-lm3532.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ static void gpio_set_low_action(void *data)
551551

552552
static int lm3532_parse_node(struct lm3532_data *priv)
553553
{
554-
struct fwnode_handle *child = NULL;
555554
struct lm3532_led *led;
556555
int control_bank;
557556
u32 ramp_time;
@@ -587,7 +586,7 @@ static int lm3532_parse_node(struct lm3532_data *priv)
587586
else
588587
priv->runtime_ramp_down = lm3532_get_ramp_index(ramp_time);
589588

590-
device_for_each_child_node(priv->dev, child) {
589+
device_for_each_child_node_scoped(priv->dev, child) {
591590
struct led_init_data idata = {
592591
.fwnode = child,
593592
.default_label = ":",
@@ -599,7 +598,7 @@ static int lm3532_parse_node(struct lm3532_data *priv)
599598
ret = fwnode_property_read_u32(child, "reg", &control_bank);
600599
if (ret) {
601600
dev_err(&priv->client->dev, "reg property missing\n");
602-
goto child_out;
601+
return ret;
603602
}
604603

605604
if (control_bank > LM3532_CONTROL_C) {
@@ -613,7 +612,7 @@ static int lm3532_parse_node(struct lm3532_data *priv)
613612
&led->mode);
614613
if (ret) {
615614
dev_err(&priv->client->dev, "ti,led-mode property missing\n");
616-
goto child_out;
615+
return ret;
617616
}
618617

619618
if (fwnode_property_present(child, "led-max-microamp") &&
@@ -647,7 +646,7 @@ static int lm3532_parse_node(struct lm3532_data *priv)
647646
led->num_leds);
648647
if (ret) {
649648
dev_err(&priv->client->dev, "led-sources property missing\n");
650-
goto child_out;
649+
return ret;
651650
}
652651

653652
led->priv = priv;
@@ -657,23 +656,20 @@ static int lm3532_parse_node(struct lm3532_data *priv)
657656
if (ret) {
658657
dev_err(&priv->client->dev, "led register err: %d\n",
659658
ret);
660-
goto child_out;
659+
return ret;
661660
}
662661

663662
ret = lm3532_init_registers(led);
664663
if (ret) {
665664
dev_err(&priv->client->dev, "register init err: %d\n",
666665
ret);
667-
goto child_out;
666+
return ret;
668667
}
669668

670669
i++;
671670
}
672-
return 0;
673671

674-
child_out:
675-
fwnode_handle_put(child);
676-
return ret;
672+
return 0;
677673
}
678674

679675
static int lm3532_probe(struct i2c_client *client)

0 commit comments

Comments
 (0)