12121313 */
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
169167static inline struct mc13xxx_leds_platform_data __init * mc13xxx_led_probe_dt (
0 commit comments