[PATCH] rtc: ftrtc010: fix clock resource leak on probe failure

Liu Dalin posted 1 patch 1 month ago
drivers/rtc/rtc-ftrtc010.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] rtc: ftrtc010: fix clock resource leak on probe failure
Posted by Liu Dalin 1 month ago
When devm_rtc_register_device() fails, ftrtc010_rtc_probe() returns
the error directly without releasing clocks obtained via
clk_prepare_enable(). This leaks both extclk and pclk resources,
which may prevent subsequent probe attempts or module removal.

Capture the return value and jump to the error handling path to
properly release clocks via clk_disable_unprepare().

Fixes smatch warnings:
- drivers/rtc/rtc-ftrtc010.c:189 ftrtc010_rtc_probe() warn:
  'rtc->extclk' from clk_prepare_enable() not released on lines: 183.
- drivers/rtc/rtc-ftrtc010.c:189 ftrtc010_rtc_probe() warn:
  'rtc->pclk' from clk_prepare_enable() not released on lines: 183.

Fixes: fdcfd854333b ("rtc: rework rtc_register_device() resource management")
Assisted-by: smatch:2.0 [static analysis]
Signed-off-by: Liu Dalin <liudalin@kylinsec.com.cn>
---
 drivers/rtc/rtc-ftrtc010.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ftrtc010.c b/drivers/rtc/rtc-ftrtc010.c
index 98fa0f518303..512790bc3f2b 100644
--- a/drivers/rtc/rtc-ftrtc010.c
+++ b/drivers/rtc/rtc-ftrtc010.c
@@ -180,7 +180,11 @@ static int ftrtc010_rtc_probe(struct platform_device *pdev)
 	if (unlikely(ret))
 		goto err_disable_extclk;
 
-	return devm_rtc_register_device(rtc_dev);
+	ret = devm_rtc_register_device(rtc_dev);
+	if (ret)
+		goto err_disable_extclk;
+
+	return 0;
 
 err_disable_extclk:
 	clk_disable_unprepare(rtc->extclk);
-- 
2.43.0
Re: [PATCH] rtc: ftrtc010: fix clock resource leak on probe failure
Posted by Linus Walleij 1 week, 5 days ago
On Thu, Aug 27, 2026 at 3:58 AM Liu Dalin <liudalin@kylinsec.com.cn> wrote:

> When devm_rtc_register_device() fails, ftrtc010_rtc_probe() returns
> the error directly without releasing clocks obtained via
> clk_prepare_enable(). This leaks both extclk and pclk resources,
> which may prevent subsequent probe attempts or module removal.
>
> Capture the return value and jump to the error handling path to
> properly release clocks via clk_disable_unprepare().
>
> Fixes smatch warnings:
> - drivers/rtc/rtc-ftrtc010.c:189 ftrtc010_rtc_probe() warn:
>   'rtc->extclk' from clk_prepare_enable() not released on lines: 183.
> - drivers/rtc/rtc-ftrtc010.c:189 ftrtc010_rtc_probe() warn:
>   'rtc->pclk' from clk_prepare_enable() not released on lines: 183.
>
> Fixes: fdcfd854333b ("rtc: rework rtc_register_device() resource management")
> Assisted-by: smatch:2.0 [static analysis]
> Signed-off-by: Liu Dalin <liudalin@kylinsec.com.cn>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij