Commit e98a7f1f authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Lee Jones

leds: mc13783: Use scoped device node handling to simplify error paths

Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the 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-11-1d0292802470@linaro.orgSigned-off-by: default avatarLee Jones <lee@kernel.org>
parent 9d4cfee0
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* Eric Miao <eric.miao@marvell.com> * Eric Miao <eric.miao@marvell.com>
*/ */
#include <linux/cleanup.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -113,7 +114,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( ...@@ -113,7 +114,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
{ {
struct mc13xxx_leds *leds = platform_get_drvdata(pdev); struct mc13xxx_leds *leds = platform_get_drvdata(pdev);
struct mc13xxx_leds_platform_data *pdata; struct mc13xxx_leds_platform_data *pdata;
struct device_node *parent, *child; struct device_node *child;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
int i = 0, ret = -ENODATA; int i = 0, ret = -ENODATA;
...@@ -121,24 +122,23 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( ...@@ -121,24 +122,23 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
if (!pdata) if (!pdata)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
parent = of_get_child_by_name(dev_of_node(dev->parent), "leds"); struct device_node *parent __free(device_node) =
of_get_child_by_name(dev_of_node(dev->parent), "leds");
if (!parent) if (!parent)
goto out_node_put; return ERR_PTR(-ENODATA);
ret = of_property_read_u32_array(parent, "led-control", ret = of_property_read_u32_array(parent, "led-control",
pdata->led_control, pdata->led_control,
leds->devtype->num_regs); leds->devtype->num_regs);
if (ret) if (ret)
goto out_node_put; return ERR_PTR(ret);
pdata->num_leds = of_get_available_child_count(parent); pdata->num_leds = of_get_available_child_count(parent);
pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led), pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led),
GFP_KERNEL); GFP_KERNEL);
if (!pdata->led) { if (!pdata->led)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto out_node_put;
}
for_each_available_child_of_node(parent, child) { for_each_available_child_of_node(parent, child) {
const char *str; const char *str;
...@@ -158,12 +158,10 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( ...@@ -158,12 +158,10 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
} }
pdata->num_leds = i; pdata->num_leds = i;
ret = i > 0 ? 0 : -ENODATA; if (i <= 0)
return ERR_PTR(-ENODATA);
out_node_put:
of_node_put(parent);
return ret ? ERR_PTR(ret) : pdata; return pdata;
} }
#else #else
static inline struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( static inline struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
......
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