Message ID | 20240814-b4-cleanup-h-of-node-put-usb-v1-9-95481b9682bc@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | usb: dwc3: various cleanups | expand |
On Wed, Aug 14, 2024, Krzysztof Kozlowski wrote: > 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> > --- > drivers/usb/dwc3/dwc3-rtk.c | 19 +++++++------------ > 1 file changed, 7 insertions(+), 12 deletions(-) > > diff --git a/drivers/usb/dwc3/dwc3-rtk.c b/drivers/usb/dwc3/dwc3-rtk.c > index 3cd6b184551c..1e3ec2084286 100644 > --- a/drivers/usb/dwc3/dwc3-rtk.c > +++ b/drivers/usb/dwc3/dwc3-rtk.c > @@ -6,6 +6,7 @@ > * > */ > > +#include <linux/cleanup.h> > #include <linux/module.h> > #include <linux/kernel.h> > #include <linux/platform_device.h> > @@ -173,23 +174,20 @@ static const char *const speed_names[] = { > > static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np) > { > - struct device_node *dwc3_np; > const char *maximum_speed; > int ret; > > - dwc3_np = of_get_compatible_child(np, "snps,dwc3"); > + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(np, > + "snps,dwc3"); > if (!dwc3_np) > return USB_SPEED_UNKNOWN; > > ret = of_property_read_string(dwc3_np, "maximum-speed", &maximum_speed); > if (ret < 0) > - goto out; > + return ret; > > ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); > > -out: > - of_node_put(dwc3_np); > - > return (ret < 0) ? USB_SPEED_UNKNOWN : ret; > } > > @@ -276,7 +274,6 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) > struct device_node *node = dev->of_node; > struct platform_device *dwc3_pdev; > struct device *dwc3_dev; > - struct device_node *dwc3_node; > enum usb_dr_mode dr_mode; > int ret = 0; > > @@ -290,7 +287,8 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) > return ret; > } > > - dwc3_node = of_get_compatible_child(node, "snps,dwc3"); > + struct device_node *dwc3_node __free(device_node) = of_get_compatible_child(node, > + "snps,dwc3"); > if (!dwc3_node) { > dev_err(dev, "failed to find dwc3 core node\n"); > ret = -ENODEV; > @@ -301,7 +299,7 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) > if (!dwc3_pdev) { > dev_err(dev, "failed to find dwc3 core platform_device\n"); > ret = -ENODEV; > - goto err_node_put; > + goto depopulate; > } > > dwc3_dev = &dwc3_pdev->dev; > @@ -343,14 +341,11 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) > switch_usb2_role(rtk, rtk->cur_role); > > platform_device_put(dwc3_pdev); > - of_node_put(dwc3_node); > > return 0; > > err_pdev_put: > platform_device_put(dwc3_pdev); > -err_node_put: > - of_node_put(dwc3_node); > depopulate: > of_platform_depopulate(dev); > > > -- > 2.43.0 > Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com> Thanks, Thinh
diff --git a/drivers/usb/dwc3/dwc3-rtk.c b/drivers/usb/dwc3/dwc3-rtk.c index 3cd6b184551c..1e3ec2084286 100644 --- a/drivers/usb/dwc3/dwc3-rtk.c +++ b/drivers/usb/dwc3/dwc3-rtk.c @@ -6,6 +6,7 @@ * */ +#include <linux/cleanup.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/platform_device.h> @@ -173,23 +174,20 @@ static const char *const speed_names[] = { static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np) { - struct device_node *dwc3_np; const char *maximum_speed; int ret; - dwc3_np = of_get_compatible_child(np, "snps,dwc3"); + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(np, + "snps,dwc3"); if (!dwc3_np) return USB_SPEED_UNKNOWN; ret = of_property_read_string(dwc3_np, "maximum-speed", &maximum_speed); if (ret < 0) - goto out; + return ret; ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); -out: - of_node_put(dwc3_np); - return (ret < 0) ? USB_SPEED_UNKNOWN : ret; } @@ -276,7 +274,6 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) struct device_node *node = dev->of_node; struct platform_device *dwc3_pdev; struct device *dwc3_dev; - struct device_node *dwc3_node; enum usb_dr_mode dr_mode; int ret = 0; @@ -290,7 +287,8 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) return ret; } - dwc3_node = of_get_compatible_child(node, "snps,dwc3"); + struct device_node *dwc3_node __free(device_node) = of_get_compatible_child(node, + "snps,dwc3"); if (!dwc3_node) { dev_err(dev, "failed to find dwc3 core node\n"); ret = -ENODEV; @@ -301,7 +299,7 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) if (!dwc3_pdev) { dev_err(dev, "failed to find dwc3 core platform_device\n"); ret = -ENODEV; - goto err_node_put; + goto depopulate; } dwc3_dev = &dwc3_pdev->dev; @@ -343,14 +341,11 @@ static int dwc3_rtk_probe_dwc3_core(struct dwc3_rtk *rtk) switch_usb2_role(rtk, rtk->cur_role); platform_device_put(dwc3_pdev); - of_node_put(dwc3_node); return 0; err_pdev_put: platform_device_put(dwc3_pdev); -err_node_put: - of_node_put(dwc3_node); depopulate: of_platform_depopulate(dev);
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> --- drivers/usb/dwc3/dwc3-rtk.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)