Skip to content

Commit e98a7f1

Browse files
krzklag-linaro
authored andcommitted
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: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 9d4cfee commit e98a7f1

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

drivers/leds/leds-mc13783.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Eric Miao <[email protected]>
1313
*/
1414

15+
#include <linux/cleanup.h>
1516
#include <linux/module.h>
1617
#include <linux/kernel.h>
1718
#include <linux/platform_device.h>
@@ -113,32 +114,31 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
113114
{
114115
struct mc13xxx_leds *leds = platform_get_drvdata(pdev);
115116
struct mc13xxx_leds_platform_data *pdata;
116-
struct device_node *parent, *child;
117+
struct device_node *child;
117118
struct device *dev = &pdev->dev;
118119
int i = 0, ret = -ENODATA;
119120

120121
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
121122
if (!pdata)
122123
return ERR_PTR(-ENOMEM);
123124

124-
parent = of_get_child_by_name(dev_of_node(dev->parent), "leds");
125+
struct device_node *parent __free(device_node) =
126+
of_get_child_by_name(dev_of_node(dev->parent), "leds");
125127
if (!parent)
126-
goto out_node_put;
128+
return ERR_PTR(-ENODATA);
127129

128130
ret = of_property_read_u32_array(parent, "led-control",
129131
pdata->led_control,
130132
leds->devtype->num_regs);
131133
if (ret)
132-
goto out_node_put;
134+
return ERR_PTR(ret);
133135

134136
pdata->num_leds = of_get_available_child_count(parent);
135137

136138
pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led),
137139
GFP_KERNEL);
138-
if (!pdata->led) {
139-
ret = -ENOMEM;
140-
goto out_node_put;
141-
}
140+
if (!pdata->led)
141+
return ERR_PTR(-ENOMEM);
142142

143143
for_each_available_child_of_node(parent, child) {
144144
const char *str;
@@ -158,12 +158,10 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
158158
}
159159

160160
pdata->num_leds = i;
161-
ret = i > 0 ? 0 : -ENODATA;
162-
163-
out_node_put:
164-
of_node_put(parent);
161+
if (i <= 0)
162+
return ERR_PTR(-ENODATA);
165163

166-
return ret ? ERR_PTR(ret) : pdata;
164+
return pdata;
167165
}
168166
#else
169167
static inline struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(

0 commit comments

Comments
 (0)