Commit 84e2b97f authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Lee Jones

leds: mt6323: Simplify with scoped for each OF child loop

Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.
Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240816-cleanup-h-of-node-put-var-v1-12-1d0292802470@linaro.orgSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent e98a7f1f
...@@ -527,7 +527,6 @@ static int mt6323_led_probe(struct platform_device *pdev) ...@@ -527,7 +527,6 @@ static int mt6323_led_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev_of_node(dev); struct device_node *np = dev_of_node(dev);
struct device_node *child;
struct mt6397_chip *hw = dev_get_drvdata(dev->parent); struct mt6397_chip *hw = dev_get_drvdata(dev->parent);
struct mt6323_leds *leds; struct mt6323_leds *leds;
struct mt6323_led *led; struct mt6323_led *led;
...@@ -565,28 +564,25 @@ static int mt6323_led_probe(struct platform_device *pdev) ...@@ -565,28 +564,25 @@ static int mt6323_led_probe(struct platform_device *pdev)
return ret; return ret;
} }
for_each_available_child_of_node(np, child) { for_each_available_child_of_node_scoped(np, child) {
struct led_init_data init_data = {}; struct led_init_data init_data = {};
bool is_wled; bool is_wled;
ret = of_property_read_u32(child, "reg", &reg); ret = of_property_read_u32(child, "reg", &reg);
if (ret) { if (ret) {
dev_err(dev, "Failed to read led 'reg' property\n"); dev_err(dev, "Failed to read led 'reg' property\n");
goto put_child_node; return ret;
} }
if (reg >= max_leds || reg >= MAX_SUPPORTED_LEDS || if (reg >= max_leds || reg >= MAX_SUPPORTED_LEDS ||
leds->led[reg]) { leds->led[reg]) {
dev_err(dev, "Invalid led reg %u\n", reg); dev_err(dev, "Invalid led reg %u\n", reg);
ret = -EINVAL; return -EINVAL;
goto put_child_node;
} }
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led) { if (!led)
ret = -ENOMEM; return -ENOMEM;
goto put_child_node;
}
is_wled = of_property_read_bool(child, "mediatek,is-wled"); is_wled = of_property_read_bool(child, "mediatek,is-wled");
...@@ -612,7 +608,7 @@ static int mt6323_led_probe(struct platform_device *pdev) ...@@ -612,7 +608,7 @@ static int mt6323_led_probe(struct platform_device *pdev)
if (ret < 0) { if (ret < 0) {
dev_err(leds->dev, dev_err(leds->dev,
"Failed to LED set default from devicetree\n"); "Failed to LED set default from devicetree\n");
goto put_child_node; return ret;
} }
init_data.fwnode = of_fwnode_handle(child); init_data.fwnode = of_fwnode_handle(child);
...@@ -621,15 +617,11 @@ static int mt6323_led_probe(struct platform_device *pdev) ...@@ -621,15 +617,11 @@ static int mt6323_led_probe(struct platform_device *pdev)
&init_data); &init_data);
if (ret) { if (ret) {
dev_err(dev, "Failed to register LED: %d\n", ret); dev_err(dev, "Failed to register LED: %d\n", ret);
goto put_child_node; return ret;
} }
} }
return 0; return 0;
put_child_node:
of_node_put(child);
return ret;
} }
static void mt6323_led_remove(struct platform_device *pdev) static void mt6323_led_remove(struct platform_device *pdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment