Skip to content

Commit bf3fba7

Browse files
javiercarrascocruzlag-linaro
authored andcommitted
leds: rgb: 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(). After switching to the scoped variant, there is no longer need for a jump to 'fwnode_release', as an immediate return is possible. Given that the loop is called in the probe function, and it already uses dev_err_probe(), the common "dev_err() + return" has been updated as well. Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-18-95c0614b38c8@gmail.com Signed-off-by: Lee Jones <[email protected]>
1 parent 4825963 commit bf3fba7

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

drivers/leds/rgb/leds-mt6370-rgb.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ static int mt6370_leds_probe(struct platform_device *pdev)
905905
{
906906
struct device *dev = &pdev->dev;
907907
struct mt6370_priv *priv;
908-
struct fwnode_handle *child;
909908
size_t count;
910909
unsigned int i = 0;
911910
int ret;
@@ -936,37 +935,27 @@ static int mt6370_leds_probe(struct platform_device *pdev)
936935
if (ret)
937936
return dev_err_probe(dev, ret, "Failed to allocate regmap field\n");
938937

939-
device_for_each_child_node(dev, child) {
938+
device_for_each_child_node_scoped(dev, child) {
940939
struct mt6370_led *led = priv->leds + i++;
941940
struct led_init_data init_data = { .fwnode = child };
942941
u32 reg, color;
943942

944943
ret = fwnode_property_read_u32(child, "reg", &reg);
945-
if (ret) {
946-
dev_err(dev, "Failed to parse reg property\n");
947-
goto fwnode_release;
948-
}
944+
if (ret)
945+
dev_err_probe(dev, ret, "Failed to parse reg property\n");
949946

950-
if (reg >= MT6370_MAX_LEDS) {
951-
ret = -EINVAL;
952-
dev_err(dev, "Error reg property number\n");
953-
goto fwnode_release;
954-
}
947+
if (reg >= MT6370_MAX_LEDS)
948+
return dev_err_probe(dev, -EINVAL, "Error reg property number\n");
955949

956950
ret = fwnode_property_read_u32(child, "color", &color);
957-
if (ret) {
958-
dev_err(dev, "Failed to parse color property\n");
959-
goto fwnode_release;
960-
}
951+
if (ret)
952+
return dev_err_probe(dev, ret, "Failed to parse color property\n");
961953

962954
if (color == LED_COLOR_ID_RGB || color == LED_COLOR_ID_MULTI)
963955
reg = MT6370_VIRTUAL_MULTICOLOR;
964956

965-
if (priv->leds_active & BIT(reg)) {
966-
ret = -EINVAL;
967-
dev_err(dev, "Duplicate reg property\n");
968-
goto fwnode_release;
969-
}
957+
if (priv->leds_active & BIT(reg))
958+
return dev_err_probe(dev, -EINVAL, "Duplicate reg property\n");
970959

971960
priv->leds_active |= BIT(reg);
972961

@@ -975,18 +964,14 @@ static int mt6370_leds_probe(struct platform_device *pdev)
975964

976965
ret = mt6370_init_led_properties(dev, led, &init_data);
977966
if (ret)
978-
goto fwnode_release;
967+
return ret;
979968

980969
ret = mt6370_led_register(dev, led, &init_data);
981970
if (ret)
982-
goto fwnode_release;
971+
return ret;
983972
}
984973

985974
return 0;
986-
987-
fwnode_release:
988-
fwnode_handle_put(child);
989-
return ret;
990975
}
991976

992977
static const struct of_device_id mt6370_rgbled_device_table[] = {

0 commit comments

Comments
 (0)