diff mbox series

rtc: at91sam9: fix call balance of rtc->sclk handling routines

Message ID 20250303140229.642959-1-mordan@ispras.ru (mailing list archive)
State New
Headers show
Series rtc: at91sam9: fix call balance of rtc->sclk handling routines | expand

Commit Message

Vitalii Mordan March 3, 2025, 2:02 p.m. UTC
If rtc->sclk was enabled in at91_rtc_probe(), it must be disabled in
all error paths to ensure proper cleanup. However, if
devm_rtc_register_device() returns an error in at91_rtc_probe(), the
rtc->sclk clock will not be disabled.

Use the devm_clk_get_enabled() helper function to ensure proper call
balance for rtc->sclk.

Found by Linux Verification Center (linuxtesting.org) with Klever.

Fixes: a975f47f6e9a ("rtc: at91sam9: use clk API instead of relying on AT91_SLOW_CLOCK")
Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
---
 drivers/rtc/rtc-at91sam9.c | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 38991cca5930..f4b7cf37397f 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -375,21 +375,16 @@  static int at91_rtc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	rtc->sclk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(rtc->sclk))
+	rtc->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
+	if (IS_ERR(rtc->sclk)) {
+		dev_err(&pdev->dev, "Could not get and enable slow clock\n");
 		return PTR_ERR(rtc->sclk);
-
-	ret = clk_prepare_enable(rtc->sclk);
-	if (ret) {
-		dev_err(&pdev->dev, "Could not enable slow clock\n");
-		return ret;
 	}
 
 	sclk_rate = clk_get_rate(rtc->sclk);
 	if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) {
 		dev_err(&pdev->dev, "Invalid slow clock rate\n");
-		ret = -EINVAL;
-		goto err_clk;
+		return -EINVAL;
 	}
 
 	mr = rtt_readl(rtc, MR);
@@ -405,10 +400,8 @@  static int at91_rtc_probe(struct platform_device *pdev)
 	rtt_writel(rtc, MR, mr);
 
 	rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
-	if (IS_ERR(rtc->rtcdev)) {
-		ret = PTR_ERR(rtc->rtcdev);
-		goto err_clk;
-	}
+	if (IS_ERR(rtc->rtcdev))
+		return PTR_ERR(rtc->rtcdev);
 
 	rtc->rtcdev->ops = &at91_rtc_ops;
 	rtc->rtcdev->range_max = U32_MAX;
@@ -419,7 +412,7 @@  static int at91_rtc_probe(struct platform_device *pdev)
 			       dev_name(&rtc->rtcdev->dev), rtc);
 	if (ret) {
 		dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
-		goto err_clk;
+		return ret;
 	}
 
 	/* NOTE:  sam9260 rev A silicon has a ROM bug which resets the
@@ -433,11 +426,6 @@  static int at91_rtc_probe(struct platform_device *pdev)
 			 dev_name(&rtc->rtcdev->dev));
 
 	return devm_rtc_register_device(rtc->rtcdev);
-
-err_clk:
-	clk_disable_unprepare(rtc->sclk);
-
-	return ret;
 }
 
 /*
@@ -450,8 +438,6 @@  static void at91_rtc_remove(struct platform_device *pdev)
 
 	/* disable all interrupts */
 	rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
-
-	clk_disable_unprepare(rtc->sclk);
 }
 
 static void at91_rtc_shutdown(struct platform_device *pdev)