[PATCH] xtensa: time: Fix clk reference leak in calibrate_ccount()

blaze posted 1 patch 2 weeks, 1 day ago
arch/xtensa/kernel/time.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] xtensa: time: Fix clk reference leak in calibrate_ccount()
Posted by blaze 2 weeks, 1 day ago
From: 赵宇 <1466528493@qq.com>

In calibrate_ccount(), of_clk_get() acquires a reference to the CPU
clock, but clk_put() is never called to release it. The clock
reference is used only to read the frequency via clk_get_rate(),
then the function returns immediately, leaking the reference.

Fix this by calling clk_put(clk) before returning.

Signed-off-by: 赵宇 <1466528493@qq.com>
---
 arch/xtensa/kernel/time.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
index 09fda6a..bccc0e9 100644
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -152,6 +152,7 @@ static void __init calibrate_ccount(void)
 		of_node_put(cpu);
 		if (!IS_ERR(clk)) {
 			ccount_freq = clk_get_rate(clk);
+			clk_put(clk);
 			return;
 		} else {
 			pr_warn("%s: CPU input clock not found\n",
-- 
2.53.0.windows.1

Re: [PATCH] xtensa: time: Fix clk reference leak in calibrate_ccount()
Posted by Max Filippov 2 weeks, 1 day ago
On Wed, Sep 9, 2026 at 10:07 PM blaze <1466528493@qq.com> wrote:
>
> From: 赵宇 <1466528493@qq.com>
>
> In calibrate_ccount(), of_clk_get() acquires a reference to the CPU
> clock, but clk_put() is never called to release it. The clock
> reference is used only to read the frequency via clk_get_rate(),
> then the function returns immediately, leaking the reference.
>
> Fix this by calling clk_put(clk) before returning.
>
> Signed-off-by: 赵宇 <1466528493@qq.com>
> ---
>  arch/xtensa/kernel/time.c | 1 +
>  1 file changed, 1 insertion(+)

Thank you for taking time to explain and resubmit.
Applied to my xtensa tree.

-- 
Thanks.
-- Max