* [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll()
@ 2022-11-23 3:22 Xiu Jianfeng
2022-11-23 9:01 ` Heiko Stuebner
0 siblings, 1 reply; 3+ messages in thread
From: Xiu Jianfeng @ 2022-11-23 3:22 UTC (permalink / raw)
To: mturquette, sboyd, heiko, mturquette
Cc: linux-clk, linux-arm-kernel, linux-rockchip, linux-kernel
If clk_register() fails, @pll->rate_table may have allocated memory by
kmemdup(), so it needs to be freed, otherwise will cause memory leak
issue, this patch fixes it.
Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
drivers/clk/rockchip/clk-pll.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index 4b9840994295..dc4ce280d125 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -1200,6 +1200,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
clk_unregister(mux_clk);
mux_clk = pll_clk;
err_mux:
+ kfree(pll->rate_table);
kfree(pll);
return mux_clk;
}
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll()
2022-11-23 3:22 [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll() Xiu Jianfeng
@ 2022-11-23 9:01 ` Heiko Stuebner
2022-11-23 9:21 ` xiujianfeng
0 siblings, 1 reply; 3+ messages in thread
From: Heiko Stuebner @ 2022-11-23 9:01 UTC (permalink / raw)
To: mturquette, sboyd, mturquette, Xiu Jianfeng
Cc: linux-clk, linux-arm-kernel, linux-rockchip, linux-kernel
Hi,
Am Mittwoch, 23. November 2022, 04:22:37 CET schrieb Xiu Jianfeng:
> If clk_register() fails, @pll->rate_table may have allocated memory by
> kmemdup(), so it needs to be freed, otherwise will cause memory leak
> issue, this patch fixes it.
>
> Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066")
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
> drivers/clk/rockchip/clk-pll.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> index 4b9840994295..dc4ce280d125 100644
> --- a/drivers/clk/rockchip/clk-pll.c
> +++ b/drivers/clk/rockchip/clk-pll.c
> @@ -1200,6 +1200,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
> clk_unregister(mux_clk);
> mux_clk = pll_clk;
> err_mux:
> + kfree(pll->rate_table);
I think this free needs to go up to the err_pll block.
In the code it is
- clk_register(pll_mux->hw) -> err_mux
- kmemdup
- clk_register(pll->hw) -> err_pll
so the kfree for the rate-table should probably
be at
err_pll:
kfree(rate_table)
clk_unregister(mux_clk);
...
Heiko
> kfree(pll);
> return mux_clk;
> }
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll()
2022-11-23 9:01 ` Heiko Stuebner
@ 2022-11-23 9:21 ` xiujianfeng
0 siblings, 0 replies; 3+ messages in thread
From: xiujianfeng @ 2022-11-23 9:21 UTC (permalink / raw)
To: Heiko Stuebner, mturquette, sboyd, mturquette
Cc: linux-clk, linux-arm-kernel, linux-rockchip, linux-kernel
Hi,
在 2022/11/23 17:01, Heiko Stuebner 写道:
> Hi,
>
> Am Mittwoch, 23. November 2022, 04:22:37 CET schrieb Xiu Jianfeng:
>> If clk_register() fails, @pll->rate_table may have allocated memory by
>> kmemdup(), so it needs to be freed, otherwise will cause memory leak
>> issue, this patch fixes it.
>>
>> Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066")
>> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
>> ---
>> drivers/clk/rockchip/clk-pll.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
>> index 4b9840994295..dc4ce280d125 100644
>> --- a/drivers/clk/rockchip/clk-pll.c
>> +++ b/drivers/clk/rockchip/clk-pll.c
>> @@ -1200,6 +1200,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
>> clk_unregister(mux_clk);
>> mux_clk = pll_clk;
>> err_mux:
>> + kfree(pll->rate_table);
>
> I think this free needs to go up to the err_pll block.
>
> In the code it is
> - clk_register(pll_mux->hw) -> err_mux
> - kmemdup
> - clk_register(pll->hw) -> err_pll
>
> so the kfree for the rate-table should probably
> be at
> err_pll:
> kfree(rate_table)
Thanks for you review, I think here should be kfree(pll->rate_table)
instead of kfree(rate_table), because @rate_table is the intput param
while pll->rate_table is the new allocated memory.
v2 already sent.
> clk_unregister(mux_clk);
> ...
>
>
> Heiko
>
>> kfree(pll);
>> return mux_clk;
>> }
>>
>
>
>
>
>
> .
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-23 9:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-23 3:22 [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll() Xiu Jianfeng
2022-11-23 9:01 ` Heiko Stuebner
2022-11-23 9:21 ` xiujianfeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).