Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: dwc3: rtk: 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 <krzysztof.kozlowski@linaro.org>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20240814-b4-cleanup-h-of-node-put-usb-v1-9-95481b9682bc@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Krzysztof Kozlowski and committed by
Greg Kroah-Hartman
f93e96c5 17d206a3

+7 -12
+7 -12
drivers/usb/dwc3/dwc3-rtk.c
··· 6 6 * 7 7 */ 8 8 9 + #include <linux/cleanup.h> 9 10 #include <linux/module.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/platform_device.h> ··· 174 173 175 174 static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np) 176 175 { 177 - struct device_node *dwc3_np; 178 176 const char *maximum_speed; 179 177 int ret; 180 178 181 - dwc3_np = of_get_compatible_child(np, "snps,dwc3"); 179 + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(np, 180 + "snps,dwc3"); 182 181 if (!dwc3_np) 183 182 return USB_SPEED_UNKNOWN; 184 183 185 184 ret = of_property_read_string(dwc3_np, "maximum-speed", &maximum_speed); 186 185 if (ret < 0) 187 - goto out; 186 + return ret; 188 187 189 188 ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); 190 - 191 - out: 192 - of_node_put(dwc3_np); 193 189 194 190 return (ret < 0) ? USB_SPEED_UNKNOWN : ret; 195 191 } ··· 274 276 struct device_node *node = dev->of_node; 275 277 struct platform_device *dwc3_pdev; 276 278 struct device *dwc3_dev; 277 - struct device_node *dwc3_node; 278 279 enum usb_dr_mode dr_mode; 279 280 int ret = 0; 280 281 ··· 287 290 return ret; 288 291 } 289 292 290 - dwc3_node = of_get_compatible_child(node, "snps,dwc3"); 293 + struct device_node *dwc3_node __free(device_node) = of_get_compatible_child(node, 294 + "snps,dwc3"); 291 295 if (!dwc3_node) { 292 296 dev_err(dev, "failed to find dwc3 core node\n"); 293 297 ret = -ENODEV; ··· 299 301 if (!dwc3_pdev) { 300 302 dev_err(dev, "failed to find dwc3 core platform_device\n"); 301 303 ret = -ENODEV; 302 - goto err_node_put; 304 + goto depopulate; 303 305 } 304 306 305 307 dwc3_dev = &dwc3_pdev->dev; ··· 341 343 switch_usb2_role(rtk, rtk->cur_role); 342 344 343 345 platform_device_put(dwc3_pdev); 344 - of_node_put(dwc3_node); 345 346 346 347 return 0; 347 348 348 349 err_pdev_put: 349 350 platform_device_put(dwc3_pdev); 350 - err_node_put: 351 - of_node_put(dwc3_node); 352 351 depopulate: 353 352 of_platform_depopulate(dev); 354 353