66 *
77 */
88
9+ #include <linux/cleanup.h>
910#include <linux/module.h>
1011#include <linux/kernel.h>
1112#include <linux/platform_device.h>
@@ -173,23 +174,20 @@ static const char *const speed_names[] = {
173174
174175static enum usb_device_speed __get_dwc3_maximum_speed (struct device_node * np )
175176{
176- struct device_node * dwc3_np ;
177177 const char * maximum_speed ;
178178 int ret ;
179179
180- dwc3_np = of_get_compatible_child (np , "snps,dwc3" );
180+ struct device_node * dwc3_np __free (device_node ) = of_get_compatible_child (np ,
181+ "snps,dwc3" );
181182 if (!dwc3_np )
182183 return USB_SPEED_UNKNOWN ;
183184
184185 ret = of_property_read_string (dwc3_np , "maximum-speed" , & maximum_speed );
185186 if (ret < 0 )
186- goto out ;
187+ return ret ;
187188
188189 ret = match_string (speed_names , ARRAY_SIZE (speed_names ), maximum_speed );
189190
190- out :
191- of_node_put (dwc3_np );
192-
193191 return (ret < 0 ) ? USB_SPEED_UNKNOWN : ret ;
194192}
195193
@@ -276,7 +274,6 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
276274 struct device_node * node = dev -> of_node ;
277275 struct platform_device * dwc3_pdev ;
278276 struct device * dwc3_dev ;
279- struct device_node * dwc3_node ;
280277 enum usb_dr_mode dr_mode ;
281278 int ret = 0 ;
282279
@@ -290,7 +287,8 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
290287 return ret ;
291288 }
292289
293- dwc3_node = of_get_compatible_child (node , "snps,dwc3" );
290+ struct device_node * dwc3_node __free (device_node ) = of_get_compatible_child (node ,
291+ "snps,dwc3" );
294292 if (!dwc3_node ) {
295293 dev_err (dev , "failed to find dwc3 core node\n" );
296294 ret = - ENODEV ;
@@ -301,7 +299,7 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
301299 if (!dwc3_pdev ) {
302300 dev_err (dev , "failed to find dwc3 core platform_device\n" );
303301 ret = - ENODEV ;
304- goto err_node_put ;
302+ goto depopulate ;
305303 }
306304
307305 dwc3_dev = & dwc3_pdev -> dev ;
@@ -343,14 +341,11 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk)
343341 switch_usb2_role (rtk , rtk -> cur_role );
344342
345343 platform_device_put (dwc3_pdev );
346- of_node_put (dwc3_node );
347344
348345 return 0 ;
349346
350347err_pdev_put :
351348 platform_device_put (dwc3_pdev );
352- err_node_put :
353- of_node_put (dwc3_node );
354349depopulate :
355350 of_platform_depopulate (dev );
356351
0 commit comments