From: Xiaoke Wang <[email protected]>
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 <[email protected]>
---
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) {
--
On 22-04-07 15:37:22, [email protected] wrote:
> From: Xiaoke Wang <[email protected]>
>
> 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 <[email protected]>
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) {
> --
On 22-04-07 15:37:22, [email protected] wrote:
> From: Xiaoke Wang <[email protected]>
>
> 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 <[email protected]>
Reviewed-by: Abel Vesa <[email protected]>
> ---
> 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) {
> --