Skip to content

Commit

Permalink
clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu()
Browse files Browse the repository at this point in the history
In __imx_clk_gpr_scu(), if imx_scu_clk_is_valid(rsrc_id) fails, then
`clk_node` which is allocated by kzalloc() is not properly released,
which may lead to memory leak.
So this patch added kfree(clk_node) on the above error path before
return ERR_PTR(-EINVAL).

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Reviewed-by: Abel Vesa <abel.vesa@nxp.com>
Link: https://lore.kernel.org/r/tencent_27FF59903EE6AB5C0D0E6D0A8E7059A59007@qq.com
Signed-off-by: Abel Vesa <abel.vesa@nxp.com>
  • Loading branch information
Xiaoke Wang authored and Abel Vesa committed Apr 12, 2022
1 parent ed713e2 commit 2759f38
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/clk/imx/clk-scu.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,10 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_na
if (!clk_node)
return ERR_PTR(-ENOMEM);

if (!imx_scu_clk_is_valid(rsrc_id))
if (!imx_scu_clk_is_valid(rsrc_id)) {
kfree(clk_node);
return ERR_PTR(-EINVAL);
}

clk = kzalloc(sizeof(*clk), GFP_KERNEL);
if (!clk) {
Expand Down

0 comments on commit 2759f38

Please sign in to comment.