diff options
author | Xiaoke Wang <xkernel.wang@foxmail.com> | 2022-04-07 09:37:22 +0200 |
---|---|---|
committer | Abel Vesa <abel.vesa@nxp.com> | 2022-04-12 13:02:02 +0200 |
commit | 2759f38b6c9551e4a1184131bc660d6a520a7cf4 (patch) | |
tree | 73d9c9d1323dfd4f8b2622e7796761dfdd1dd2bd /drivers/clk/imx | |
parent | clk: imx: Add check for kcalloc (diff) | |
download | linux-2759f38b6c9551e4a1184131bc660d6a520a7cf4.tar.xz linux-2759f38b6c9551e4a1184131bc660d6a520a7cf4.zip |
clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu()
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>
Diffstat (limited to 'drivers/clk/imx')
-rw-r--r-- | drivers/clk/imx/clk-scu.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c index 083da31dc3ea..ed3c01d2e8ae 100644 --- a/drivers/clk/imx/clk-scu.c +++ b/drivers/clk/imx/clk-scu.c @@ -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) { |