* [PATCH] clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu()
@ 2022-04-07 7:37 xkernel.wang
2022-04-08 11:55 ` Abel Vesa
2022-04-12 11:05 ` Abel Vesa
0 siblings, 2 replies; 3+ messages in thread
From: xkernel.wang @ 2022-04-07 7:37 UTC (permalink / raw)
To: abel.vesa, mturquette, sboyd, shawnguo, s.hauer
Cc: kernel, festevam, linux-imx, linux-clk, linux-arm-kernel,
linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
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>
---
drivers/clk/imx/clk-scu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
index 083da31..ed3c01d 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) {
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu()
2022-04-07 7:37 [PATCH] clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu() xkernel.wang
@ 2022-04-08 11:55 ` Abel Vesa
2022-04-12 11:05 ` Abel Vesa
1 sibling, 0 replies; 3+ messages in thread
From: Abel Vesa @ 2022-04-08 11:55 UTC (permalink / raw)
To: xkernel.wang
Cc: mturquette, sboyd, shawnguo, s.hauer, kernel, festevam,
linux-imx, linux-clk, linux-arm-kernel, linux-kernel
On 22-04-07 15:37:22, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> 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>
> ---
> drivers/clk/imx/clk-scu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
> index 083da31..ed3c01d 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) {
> --
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu()
2022-04-07 7:37 [PATCH] clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu() xkernel.wang
2022-04-08 11:55 ` Abel Vesa
@ 2022-04-12 11:05 ` Abel Vesa
1 sibling, 0 replies; 3+ messages in thread
From: Abel Vesa @ 2022-04-12 11:05 UTC (permalink / raw)
To: xkernel.wang
Cc: mturquette, sboyd, shawnguo, s.hauer, kernel, festevam,
linux-imx, linux-clk, linux-arm-kernel, linux-kernel
On 22-04-07 15:37:22, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> 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>
Applied, thanks!
> ---
> drivers/clk/imx/clk-scu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
> index 083da31..ed3c01d 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) {
> --
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-12 12:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 7:37 [PATCH] clk: imx: scu: fix a potential memory leak in __imx_clk_gpr_scu() xkernel.wang
2022-04-08 11:55 ` Abel Vesa
2022-04-12 11:05 ` Abel Vesa
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).