diff mbox series

[v2,5/7] wdt: dw: Free the clock on error

Message ID 20200807150355.287181-5-seanga2@gmail.com
State New
Delegated to: Marek Vasut
Headers show
Series [v2,1/7] wdt: dw: Switch to using fls for log2 | expand

Commit Message

Sean Anderson Aug. 7, 2020, 3:03 p.m. UTC
The clock subsystem requires that clk_free be called on clocks obtained via
clk_get_*.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

(no changes since v1)

 drivers/watchdog/designware_wdt.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index e6f5437056..189d555f29 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -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,20 @@  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);
+	return ret;
 }
 
 static const struct wdt_ops designware_wdt_ops = {