usb: dwc3: core: fix some leaks in probe
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 22 Sep 2022 11:22:08 +0000 (14:22 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Sep 2022 13:52:31 +0000 (15:52 +0200)
The dwc3_get_properties() function calls:

dwc->usb_psy = power_supply_get_by_name(usb_psy_name);

so there is some additional clean up required on these error paths.

Fixes: 6f0764b5adea ("usb: dwc3: add a power supply for current control")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/YyxFYFnP53j9sCg+@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.c

index a63d592..554e005 100644 (file)
@@ -1782,8 +1782,10 @@ static int dwc3_probe(struct platform_device *pdev)
        }
 
        dwc->reset = devm_reset_control_array_get_optional_shared(dev);
-       if (IS_ERR(dwc->reset))
-               return PTR_ERR(dwc->reset);
+       if (IS_ERR(dwc->reset)) {
+               ret = PTR_ERR(dwc->reset);
+               goto put_usb_psy;
+       }
 
        if (dev->of_node) {
                /*
@@ -1793,45 +1795,57 @@ static int dwc3_probe(struct platform_device *pdev)
                 * check for them to retain backwards compatibility.
                 */
                dwc->bus_clk = devm_clk_get_optional(dev, "bus_early");
-               if (IS_ERR(dwc->bus_clk))
-                       return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
-                                            "could not get bus clock\n");
+               if (IS_ERR(dwc->bus_clk)) {
+                       ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
+                                           "could not get bus clock\n");
+                       goto put_usb_psy;
+               }
 
                if (dwc->bus_clk == NULL) {
                        dwc->bus_clk = devm_clk_get_optional(dev, "bus_clk");
-                       if (IS_ERR(dwc->bus_clk))
-                               return dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
-                                                    "could not get bus clock\n");
+                       if (IS_ERR(dwc->bus_clk)) {
+                               ret = dev_err_probe(dev, PTR_ERR(dwc->bus_clk),
+                                                   "could not get bus clock\n");
+                               goto put_usb_psy;
+                       }
                }
 
                dwc->ref_clk = devm_clk_get_optional(dev, "ref");
-               if (IS_ERR(dwc->ref_clk))
-                       return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
-                                            "could not get ref clock\n");
+               if (IS_ERR(dwc->ref_clk)) {
+                       ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
+                                           "could not get ref clock\n");
+                       goto put_usb_psy;
+               }
 
                if (dwc->ref_clk == NULL) {
                        dwc->ref_clk = devm_clk_get_optional(dev, "ref_clk");
-                       if (IS_ERR(dwc->ref_clk))
-                               return dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
-                                                    "could not get ref clock\n");
+                       if (IS_ERR(dwc->ref_clk)) {
+                               ret = dev_err_probe(dev, PTR_ERR(dwc->ref_clk),
+                                                   "could not get ref clock\n");
+                               goto put_usb_psy;
+                       }
                }
 
                dwc->susp_clk = devm_clk_get_optional(dev, "suspend");
-               if (IS_ERR(dwc->susp_clk))
-                       return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
-                                            "could not get suspend clock\n");
+               if (IS_ERR(dwc->susp_clk)) {
+                       ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
+                                           "could not get suspend clock\n");
+                       goto put_usb_psy;
+               }
 
                if (dwc->susp_clk == NULL) {
                        dwc->susp_clk = devm_clk_get_optional(dev, "suspend_clk");
-                       if (IS_ERR(dwc->susp_clk))
-                               return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
-                                                    "could not get suspend clock\n");
+                       if (IS_ERR(dwc->susp_clk)) {
+                               ret = dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
+                                                   "could not get suspend clock\n");
+                               goto put_usb_psy;
+                       }
                }
        }
 
        ret = reset_control_deassert(dwc->reset);
        if (ret)
-               return ret;
+               goto put_usb_psy;
 
        ret = dwc3_clk_enable(dwc);
        if (ret)
@@ -1931,7 +1945,7 @@ disable_clks:
        dwc3_clk_disable(dwc);
 assert_reset:
        reset_control_assert(dwc->reset);
-
+put_usb_psy:
        if (dwc->usb_psy)
                power_supply_put(dwc->usb_psy);