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

blaze posted 1 patch 2 weeks, 2 days ago
There is a newer version of this series
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, 2 days ago
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.

Fixes: a1f31a21e0c1 ("xtensa: add clocksource")
Signed-off-by: blaze <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 0000000..1111111 100644
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -152,6 +152,7 @@ static void __init calibrate_ccount(void)
 		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.43.0
Re: [PATCH] xtensa: time: Fix clk reference leak in calibrate_ccount()
Posted by Max Filippov 2 weeks, 2 days ago
Hi,

On Tue, Sep 8, 2026 at 9:43 PM blaze <1466528493@qq.com> wrote:
> 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.
>
> Fixes: a1f31a21e0c1 ("xtensa: add clocksource")
> Signed-off-by: blaze <1466528493@qq.com>

the handle "blaze <1466528493@qq.com>" doesn't look like a known identity,
as Documentation/process/submitting-patches.rst requires, and it's one of the
first appearances of this name in the LKML. Could you please re-submit using
something less anonymous?

> ---
>  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 0000000..1111111 100644
> --- a/arch/xtensa/kernel/time.c
> +++ b/arch/xtensa/kernel/time.c
> @@ -152,6 +152,7 @@ static void __init calibrate_ccount(void)
>                 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.43.0
>

The change itself looks good, thanks.

-- Max