Skip to contentSkip to conversation

rtc: at91sam9: Use devm_clk_get_enabled() in at91_rtc_probe()

PATCH New Markus Elfring 2 participants 2 messages Nov 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: at91sam9: Use devm_clk_get_enabled() in at91_rtc_probe()

From: Markus Elfring <[email protected]>
Date: Tue, 24 Nov 2026 08:01:48 +0100

* Reuse existing functionality from devm_clk_get_enabled() instead of keeping duplicate source code.

* Delete a clk_disable_unprepare() call on an error handling path and in the implementation of the function “at91_rtc_remove”.

* Omit the label “err_clk”.

This issue was detected by using the Coccinelle software.

---
 drivers/rtc/rtc-at91sam9.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/rtc/rtc-at91sam9.c +5 -21
index cbd2f1a6c54a..6628335d6f46 100644
@@ -375,21 +375,14 @@ static int at91_rtc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	rtc->sclk = devm_clk_get(&pdev->dev, NULL);
+	rtc->sclk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(rtc->sclk))
 		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 +398,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 +410,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 +424,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 +436,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)
Signature · 1 line
2.56.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

From: Markus Elfring <[email protected]>
Date: Tue, 24 Nov 2026 08:01:48 +0100

* Reuse existing functionality from devm_clk_get_enabled() instead of keeping duplicate source code.

Quoted 8 lines

* Delete a clk_disable_unprepare() call on an error handling path and in the implementation of the function “at91_rtc_remove”.

* Omit the label “err_clk”.

This issue was detected by using the Coccinelle software.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1