12
12
13
13
*/
14
14
15
+ #include <linux/cleanup.h>
15
16
#include <linux/module.h>
16
17
#include <linux/kernel.h>
17
18
#include <linux/platform_device.h>
@@ -113,32 +114,31 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
113
114
{
114
115
struct mc13xxx_leds * leds = platform_get_drvdata (pdev );
115
116
struct mc13xxx_leds_platform_data * pdata ;
116
- struct device_node * parent , * child ;
117
+ struct device_node * child ;
117
118
struct device * dev = & pdev -> dev ;
118
119
int i = 0 , ret = - ENODATA ;
119
120
120
121
pdata = devm_kzalloc (dev , sizeof (* pdata ), GFP_KERNEL );
121
122
if (!pdata )
122
123
return ERR_PTR (- ENOMEM );
123
124
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" );
125
127
if (!parent )
126
- goto out_node_put ;
128
+ return ERR_PTR ( - ENODATA ) ;
127
129
128
130
ret = of_property_read_u32_array (parent , "led-control" ,
129
131
pdata -> led_control ,
130
132
leds -> devtype -> num_regs );
131
133
if (ret )
132
- goto out_node_put ;
134
+ return ERR_PTR ( ret ) ;
133
135
134
136
pdata -> num_leds = of_get_available_child_count (parent );
135
137
136
138
pdata -> led = devm_kcalloc (dev , pdata -> num_leds , sizeof (* pdata -> led ),
137
139
GFP_KERNEL );
138
- if (!pdata -> led ) {
139
- ret = - ENOMEM ;
140
- goto out_node_put ;
141
- }
140
+ if (!pdata -> led )
141
+ return ERR_PTR (- ENOMEM );
142
142
143
143
for_each_available_child_of_node (parent , child ) {
144
144
const char * str ;
@@ -158,12 +158,10 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
158
158
}
159
159
160
160
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 );
165
163
166
- return ret ? ERR_PTR ( ret ) : pdata ;
164
+ return pdata ;
167
165
}
168
166
#else
169
167
static inline struct mc13xxx_leds_platform_data __init * mc13xxx_led_probe_dt (
0 commit comments