]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
wdt: dw: Free the clock on error
authorSean Anderson <seanga2@gmail.com>
Thu, 11 Mar 2021 02:02:20 +0000 (21:02 -0500)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Thu, 8 Apr 2021 07:37:27 +0000 (15:37 +0800)
The clock subsystem requires that clk_free be called on clocks obtained via
clk_get_*.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/watchdog/designware_wdt.c

index 709a67fbc340b644b084d02af6edb9070e2fe0e0..9e5487168cd8b3a71411257fb24401a4e0b303ce 100644 (file)
@@ -131,11 +131,13 @@ static int designware_wdt_probe(struct udevice *dev)
 
        ret = clk_enable(&clk);
        if (ret)
-               return ret;
+               goto err;
 
        priv->clk_khz = clk_get_rate(&clk) / 1000;
-       if (!priv->clk_khz)
-               return -EINVAL;
+       if (!priv->clk_khz) {
+               ret = -EINVAL;
+               goto err;
+       }
 #else
        priv->clk_khz = CONFIG_DW_WDT_CLOCK_KHZ;
 #endif
@@ -145,15 +147,21 @@ static int designware_wdt_probe(struct udevice *dev)
 
                ret = reset_get_bulk(dev, &resets);
                if (ret)
-                       return ret;
+                       goto err;
 
                ret = reset_deassert_bulk(&resets);
                if (ret)
-                       return ret;
+                       goto err;
        }
 
        /* reset to disable the watchdog */
        return designware_wdt_stop(dev);
+
+err:
+#if CONFIG_IS_ENABLED(CLK)
+       clk_free(&clk);
+#endif
+       return ret;
 }
 
 static const struct wdt_ops designware_wdt_ops = {