clk: st: Fix memory leak in st_of_quadfs_setup()

Message ID 20221122133614.184910-1-xiujianfeng@huawei.com
State New
Headers
Series clk: st: Fix memory leak in st_of_quadfs_setup() |

Commit Message

Xiu Jianfeng Nov. 22, 2022, 1:36 p.m. UTC
  If st_clk_register_quadfs_pll() fails, @lock should be freed before goto
@err_exit, otherwise will cause meory leak issue, fix it.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 drivers/clk/st/clkgen-fsyn.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Patrice CHOTARD Nov. 22, 2022, 4:42 p.m. UTC | #1
Hi Xiu

On 11/22/22 14:36, Xiu Jianfeng wrote:
> If st_clk_register_quadfs_pll() fails, @lock should be freed before goto
> @err_exit, otherwise will cause meory leak issue, fix it.
> 
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
>  drivers/clk/st/clkgen-fsyn.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/st/clkgen-fsyn.c b/drivers/clk/st/clkgen-fsyn.c
> index d820292a381d..40df1db102a7 100644
> --- a/drivers/clk/st/clkgen-fsyn.c
> +++ b/drivers/clk/st/clkgen-fsyn.c
> @@ -1020,9 +1020,10 @@ static void __init st_of_quadfs_setup(struct device_node *np,
>  
>  	clk = st_clk_register_quadfs_pll(pll_name, clk_parent_name, datac->data,
>  			reg, lock);
> -	if (IS_ERR(clk))
> +	if (IS_ERR(clk)) {
> +		kfree(lock);
>  		goto err_exit;
> -	else
> +	} else
>  		pr_debug("%s: parent %s rate %u\n",
>  			__clk_get_name(clk),
>  			__clk_get_name(clk_get_parent(clk)),

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
  
Stephen Boyd Dec. 8, 2022, 2:27 a.m. UTC | #2
Quoting Xiu Jianfeng (2022-11-22 05:36:14)
> If st_clk_register_quadfs_pll() fails, @lock should be freed before goto
> @err_exit, otherwise will cause meory leak issue, fix it.
> 
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---

Applied to clk-next
  

Patch

diff --git a/drivers/clk/st/clkgen-fsyn.c b/drivers/clk/st/clkgen-fsyn.c
index d820292a381d..40df1db102a7 100644
--- a/drivers/clk/st/clkgen-fsyn.c
+++ b/drivers/clk/st/clkgen-fsyn.c
@@ -1020,9 +1020,10 @@  static void __init st_of_quadfs_setup(struct device_node *np,
 
 	clk = st_clk_register_quadfs_pll(pll_name, clk_parent_name, datac->data,
 			reg, lock);
-	if (IS_ERR(clk))
+	if (IS_ERR(clk)) {
+		kfree(lock);
 		goto err_exit;
-	else
+	} else
 		pr_debug("%s: parent %s rate %u\n",
 			__clk_get_name(clk),
 			__clk_get_name(clk_get_parent(clk)),