[PATCH 02/20] rtc: ma35d1: Fix clock leak in ma35d1_rtc_probe()

From: Wentao Liang

Date: Wed Sep 16 2026 - 03:07:14 EST


In ma35d1_rtc_probe(), the clock is acquired using of_clk_get() and
enabled with clk_prepare_enable(). However, if subsequent operations fail,
or when the driver is unloaded, the clock is never disabled or put,
resulting in reference count and resource leaks.

Switch to devm_clk_get_enabled() to automatically handle enabling and
resource cleanup on probe failure or driver removal.

Fixes: dc0684adf3b6 ("rtc: Add driver for Nuvoton ma35d1 rtc controller")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/rtc/rtc-ma35d1.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-ma35d1.c b/drivers/rtc/rtc-ma35d1.c
index cfcfc28060f6..43358d68565a 100644
--- a/drivers/rtc/rtc-ma35d1.c
+++ b/drivers/rtc/rtc-ma35d1.c
@@ -221,14 +221,10 @@ static int ma35d1_rtc_probe(struct platform_device *pdev)
if (IS_ERR(rtc->rtc_reg))
return PTR_ERR(rtc->rtc_reg);

- clk = of_clk_get(pdev->dev.of_node, 0);
+ clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(clk))
return dev_err_probe(&pdev->dev, PTR_ERR(clk), "failed to find rtc clock\n");

- ret = clk_prepare_enable(clk);
- if (ret)
- return ret;
-
if (!(rtc_reg_read(rtc, MA35_REG_RTC_INIT) & RTC_INIT_ACTIVE)) {
ret = ma35d1_rtc_init(rtc, RTC_INIT_TIMEOUT);
if (ret)
--
2.34.1