[PATCH] clocksource/drivers/fttmr010: Fix clk reference leak in error paths

Wentao Liang posted 1 patch 1 week, 3 days ago
drivers/clocksource/timer-fttmr010.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] clocksource/drivers/fttmr010: Fix clk reference leak in error paths
Posted by Wentao Liang 1 week, 3 days ago
fttmr010_common_init() obtains the PCLK reference with
of_clk_get_by_name() but never calls clk_put(). If clk_prepare_enable()
fails the reference is leaked directly, and every error path that jumps
to out_disable_clock only calls clk_disable_unprepare(), which releases
the prepare/enable state but not the reference obtained from
of_clk_get_by_name().

Add clk_put() to the clk_prepare_enable() failure path and to the
out_disable_clock label so the clock reference is no longer leaked. The
success path keeps PCLK enabled for the lifetime of the timer and is
left untouched.

Fixes: dd98442e17a6 ("clocksource/drivers/fttmr010: Drop Gemini specifics")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/clocksource/timer-fttmr010.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clocksource/timer-fttmr010.c b/drivers/clocksource/timer-fttmr010.c
index 308f94bfbaed..c2553851e8d6 100644
--- a/drivers/clocksource/timer-fttmr010.c
+++ b/drivers/clocksource/timer-fttmr010.c
@@ -292,6 +292,7 @@ static int __init fttmr010_common_init(struct device_node *np,
 	ret = clk_prepare_enable(clk);
 	if (ret) {
 		pr_err("failed to enable PCLK\n");
+		clk_put(clk);
 		return ret;
 	}
 
@@ -432,6 +433,7 @@ static int __init fttmr010_common_init(struct device_node *np,
 	kfree(fttmr010);
 out_disable_clock:
 	clk_disable_unprepare(clk);
+	clk_put(clk);
 
 	return ret;
 }
-- 
2.34.1
Re: [PATCH] clocksource/drivers/fttmr010: Fix clk reference leak in error paths
Posted by Linus Walleij 1 week, 1 day ago
On Tue, Sep 15, 2026 at 6:55 AM Wentao Liang <vulab@iscas.ac.cn> wrote:

> fttmr010_common_init() obtains the PCLK reference with
> of_clk_get_by_name() but never calls clk_put(). If clk_prepare_enable()
> fails the reference is leaked directly, and every error path that jumps
> to out_disable_clock only calls clk_disable_unprepare(), which releases
> the prepare/enable state but not the reference obtained from
> of_clk_get_by_name().
>
> Add clk_put() to the clk_prepare_enable() failure path and to the
> out_disable_clock label so the clock reference is no longer leaked. The
> success path keeps PCLK enabled for the lifetime of the timer and is
> left untouched.
>
> Fixes: dd98442e17a6 ("clocksource/drivers/fttmr010: Drop Gemini specifics")
> Cc: stable@vger.kernel.org

Also here. Why stable? It's not like this get exercised so much that
it makes anything on the planet unstable.

Yours,
Linus Walleij
Re: [PATCH] clocksource/drivers/fttmr010: Fix clk reference leak in error paths
Posted by Linus Walleij 1 week, 1 day ago
On Tue, Sep 15, 2026 at 6:55 AM Wentao Liang <vulab@iscas.ac.cn> wrote:

> fttmr010_common_init() obtains the PCLK reference with
> of_clk_get_by_name() but never calls clk_put(). If clk_prepare_enable()
> fails the reference is leaked directly, and every error path that jumps
> to out_disable_clock only calls clk_disable_unprepare(), which releases
> the prepare/enable state but not the reference obtained from
> of_clk_get_by_name().
>
> Add clk_put() to the clk_prepare_enable() failure path and to the
> out_disable_clock label so the clock reference is no longer leaked. The
> success path keeps PCLK enabled for the lifetime of the timer and is
> left untouched.
>
> Fixes: dd98442e17a6 ("clocksource/drivers/fttmr010: Drop Gemini specifics")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>

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

Yours,
Linus Walleij