clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
PATCH 1/1 clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
In cases where imx_clk_is_resource_owned() returns false, the code path does not handle the failure gracefully, potentially leading to a memory leak. This fix ensures proper cleanup by freeing the allocated memory for 'clk_node' before returning.
--- drivers/clk/imx/clk-scu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-scu.c +3 -1
@@ -886,8 +886,10 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_nareturn ERR_PTR (-EINVAL ); } -if (!imx_clk_is_resource_owned (rsrc_id)) +if (!imx_clk_is_resource_owned (rsrc_id)) { +kfree (clk_node);return NULL ; + } clk =kzalloc (sizeof (*clk),GFP_KERNEL );if (!clk) {
Signature · 1 line
2.25.1
Quoted 8 lines
Subject: [PATCH] clk: imx: scu: Fix memory leak in
__imx_clk_gpr_scu()In cases where
imx_clk_is_resource_owned()returns false, the code path does not handle the failure gracefully, potentially leading to a memory leak. This fix ensures proper cleanup by freeing the allocated memory for 'clk_node' before returning.Signed-off-by Kuan-Wei Chiu <[email protected]>
Abel Vesa
AppliedQuoted 6 lines · Kuan-Wei Chiu
In cases where
imx_clk_is_resource_owned()returns false, the code path does not handle the failure gracefully, potentially leading to a memory leak. This fix ensures proper cleanup by freeing the allocated memory for 'clk_node' before returning.
Applied, thanks!
[1/1] clk: imx: scu: Fix memory leak in __imx_clk_gpr_scu()
commit: 986439a9b3a32a6ac20042ec17acd443f1e7e86a
Best regards,
Signature · 1 line
Abel Vesa <[email protected]>
PATCH 1/1 clk: imx: scu: Use common error handling code in __imx_clk_gpr_scu()
In reply to Kuan-Wei ChiuFrom: Markus Elfring <[email protected]>
Date: Fri, 22 Dec 2023 10:05:32 +0100
Use another label so that a bit of exception handling can be better reused at the end of this function.
--- drivers/clk/imx/clk-scu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/clk/imx/clk-scu.c +7 -6
@@ -882,19 +882,19 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_nareturn ERR_PTR (-ENOMEM );if (!imx_scu_clk_is_valid (rsrc_id)) { -kfree (clk_node); -return ERR_PTR (-EINVAL ); + ret = -EINVAL ; + goto free_clk_node; }if (!imx_clk_is_resource_owned (rsrc_id)) { -kfree (clk_node); -return NULL ; + ret =0 ; + goto free_clk_node; } clk =kzalloc (sizeof (*clk),GFP_KERNEL );if (!clk) { -kfree (clk_node); -return ERR_PTR (-ENOMEM ); + ret = -ENOMEM ; + goto free_clk_node; } clk->rsrc_id = rsrc_id;
@@ -922,6 +922,7 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_na ret =clk_hw_register (NULL , hw);if (ret) {kfree (clk); +free_clk_node:kfree (clk_node); hw =ERR_PTR (ret); }else {
--
2.43.0
Re: [PATCH] clk: imx: scu: Use common error handling code in __imx_clk_gpr_scu()
Quoted 5 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 22 Dec 2023 10:05:32 +0100Use another label so that a bit of exception handling can be better reused at the end of this function.
Please don't send patches as reply to other(s) patches.
Quoted 47 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/clk/imx/clk-scu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/clk/imx/clk-scu.c +7
-7@@ -882,19 +882,19 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_nareturn ERR_PTR (-ENOMEM );if (!imx_scu_clk_is_valid (rsrc_id)) { -kfree (clk_node); -return ERR_PTR (-EINVAL ); + ret = -EINVAL ; + goto free_clk_node; }if (!imx_clk_is_resource_owned (rsrc_id)) { -kfree (clk_node); -return NULL ; + ret =0 ; + goto free_clk_node; } clk =kzalloc (sizeof (*clk),GFP_KERNEL );if (!clk) { -kfree (clk_node); -return ERR_PTR (-ENOMEM ); + ret = -ENOMEM ; + goto free_clk_node; } clk->rsrc_id = rsrc_id;@@ -922,6 +922,7 @@ struct clk_hw *__imx_clk_gpr_scu(const char *name, const char * const *parent_na ret =clk_hw_register (NULL , hw);if (ret) {kfree (clk); +free_clk_node:kfree (clk_node); hw =ERR_PTR (ret); }else { --2.43.0
Re: clk: imx: scu: Use common error handling code in __imx_clk_gpr_scu()
Quoted 4 lines
Quoted 2 lines
Use another label so that a bit of exception handling can be better reused at the end of this function.
Please don't send patches as reply to other(s) patches.
This is a general possibility to connect an information sources with a corresponding change idea.
Will the acceptance grow for the presented source code transformation?
Regards,
Markus
Re: clk: imx: scu: Use common error handling code in __imx_clk_gpr_scu()
Quoted 9 lines · Markus Elfring
Quoted 4 lines
Quoted 2 lines
Use another label so that a bit of exception handling can be better reused at the end of this function.
Please don't send patches as reply to other(s) patches.
This is a general possibility to connect an information sources with a corresponding change idea.
Will the acceptance grow for the presented source code transformation?
Nope, please don't do that. The b4 tool will pick up the old patch if you do this.
Quoted 2 lines
Regards,
Markus
Re: clk: imx: scu: Use common error handling code in __imx_clk_gpr_scu()
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Use another label so that a bit of exception handling can be better reused at the end of this function.
Please don't send patches as reply to other(s) patches.
This is a general possibility to connect an information sources with a corresponding change idea.
Will the acceptance grow for the presented source code transformation?Nope, please don't do that.
Do you find the proposed source code transformation reasonable (in principle)?
Quoted 1 line
The b4 tool will pick up the old patch if you do this.
Are you looking for further improvements for this development tool?
Regards,
Markus