2022-11-22 16:12:37

by Xiu Jianfeng

[permalink] [raw]
Subject: [PATCH] clk: visconti: Fix memory leak in visconti_register_pll()

@pll->rate_table has allocated memory by kmemdup(), if clk_hw_register()
fails, it should be freed, otherwise it will cause memory leak issue,
this patch fixes it.

Fixes: b4cbe606dc36 ("clk: visconti: Add support common clock driver and reset driver")
Signed-off-by: Xiu Jianfeng <[email protected]>
---
drivers/clk/visconti/pll.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c
index a484cb945d67..1f3234f22667 100644
--- a/drivers/clk/visconti/pll.c
+++ b/drivers/clk/visconti/pll.c
@@ -277,6 +277,7 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,
ret = clk_hw_register(NULL, &pll->hw);
if (ret) {
pr_err("failed to register pll clock %s : %d\n", name, ret);
+ kfree(pll->rate_table);
kfree(pll);
pll_hw_clk = ERR_PTR(ret);
}
--
2.17.1


2022-11-24 02:22:42

by Nobuhiro Iwamatsu

[permalink] [raw]
Subject: RE: [PATCH] clk: visconti: Fix memory leak in visconti_register_pll()

Hi Xiu,

Thanks for your patch!

> -----Original Message-----
> From: Xiu Jianfeng <[email protected]>
> Sent: Wednesday, November 23, 2022 12:24 AM
> To: [email protected]; [email protected]; iwamatsu nobuhiro($B4d>>(B $B?.(B
> $BMN(B $B""#S#W#C"~#A#C#T(B) <[email protected]>
> Cc: [email protected]; [email protected];
> [email protected]
> Subject: [PATCH] clk: visconti: Fix memory leak in visconti_register_pll()
>
> @pll->rate_table has allocated memory by kmemdup(), if clk_hw_register()
> fails, it should be freed, otherwise it will cause memory leak issue, this patch
> fixes it.
>
> Fixes: b4cbe606dc36 ("clk: visconti: Add support common clock driver and
> reset driver")
> Signed-off-by: Xiu Jianfeng <[email protected]>

Acked-by: Nobuhiro Iwamatsu <[email protected]>

Best regards,
Nobuhiro
> ---
> drivers/clk/visconti/pll.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c index
> a484cb945d67..1f3234f22667 100644
> --- a/drivers/clk/visconti/pll.c
> +++ b/drivers/clk/visconti/pll.c
> @@ -277,6 +277,7 @@ static struct clk_hw *visconti_register_pll(struct
> visconti_pll_provider *ctx,
> ret = clk_hw_register(NULL, &pll->hw);
> if (ret) {
> pr_err("failed to register pll clock %s : %d\n", name, ret);
> + kfree(pll->rate_table);
> kfree(pll);
> pll_hw_clk = ERR_PTR(ret);
> }
> --
> 2.17.1

2022-11-29 20:18:00

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH] clk: visconti: Fix memory leak in visconti_register_pll()

Quoting Xiu Jianfeng (2022-11-22 07:23:53)
> @pll->rate_table has allocated memory by kmemdup(), if clk_hw_register()
> fails, it should be freed, otherwise it will cause memory leak issue,
> this patch fixes it.
>
> Fixes: b4cbe606dc36 ("clk: visconti: Add support common clock driver and reset driver")
> Signed-off-by: Xiu Jianfeng <[email protected]>
> ---

Applied to clk-next