[v2] clk: rockchip: Fix memory leak in rockchip_clk_register_pll()

Message ID 20221123091201.199819-1-xiujianfeng@huawei.com
State New
Headers
Series [v2] clk: rockchip: Fix memory leak in rockchip_clk_register_pll() |

Commit Message

Xiu Jianfeng Nov. 23, 2022, 9:12 a.m. UTC
  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>

---
v2: move kfree(pll->rate_table) to the err_pll block
---
 drivers/clk/rockchip/clk-pll.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Heiko Stübner Nov. 23, 2022, 2:01 p.m. UTC | #1
On Wed, 23 Nov 2022 17:12:01 +0800, Xiu Jianfeng wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] clk: rockchip: Fix memory leak in rockchip_clk_register_pll()
      commit: 739a6a6bbdb793bd57938cb24aa5a6df89983546

Best regards,
  

Patch

diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index 4b9840994295..2d42eb628926 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -1197,6 +1197,7 @@  struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
 	return mux_clk;
 
 err_pll:
+	kfree(pll->rate_table);
 	clk_unregister(mux_clk);
 	mux_clk = pll_clk;
 err_mux: