linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH V2] clk: hisilicon: Free clk_data and unmap region obtained by of_iomap
  2020-11-09 18:09 [PATCH V2] clk: hisilicon: Free clk_data and unmap region obtained by of_iomap Dongjiu Geng
@ 2020-11-09 12:02 ` Dongjiu Geng
       [not found] ` <c6d2fe3b-3261-2c0f-f245-49bb5e63c1ed@web.de>
  1 sibling, 0 replies; 3+ messages in thread
From: Dongjiu Geng @ 2020-11-09 12:02 UTC (permalink / raw)
  To: mturquette, sboyd, linux-clk, linux-kernel, Markus Elfring

add Markus

On 2020/11/10 2:09, Dongjiu Geng wrote:
> Free memory mapping and free clk_data, if clock initialization
> is not successful.
> 
> Fixes: 75af25f581b1 ("clk: hisi: remove static variable")
> Fixes: 62ac983b6141 ("clk: hisilicon: add hi3620_mmc_clks")
> Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com>
> ---
>  drivers/clk/hisilicon/clk-hi3620.c |  8 ++++++--
>  drivers/clk/hisilicon/clk.c        | 11 ++++++-----
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c
> index a3d04c7c3da8..864d2ddfc73c 100644
> --- a/drivers/clk/hisilicon/clk-hi3620.c
> +++ b/drivers/clk/hisilicon/clk-hi3620.c
> @@ -464,11 +464,11 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
>  
>  	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
>  	if (WARN_ON(!clk_data))
> -		return;
> +		goto unmap_io;
>  
>  	clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL);
>  	if (!clk_data->clks)
> -		return;
> +		goto free_clk_data;
>  
>  	for (i = 0; i < num; i++) {
>  		struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i];
> @@ -478,6 +478,10 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
>  
>  	clk_data->clk_num = num;
>  	of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
> +free_clk_data:
> +	kfree(clk_data);
> +unmap_io:
> +	iounmap(base);
>  }
>  
>  CLK_OF_DECLARE(hi3620_mmc_clk, "hisilicon,hi3620-mmc-clock", hi3620_mmc_clk_init);
> diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
> index 54d9fdc93599..da655683710f 100644
> --- a/drivers/clk/hisilicon/clk.c
> +++ b/drivers/clk/hisilicon/clk.c
> @@ -65,25 +65,26 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
>  	base = of_iomap(np, 0);
>  	if (!base) {
>  		pr_err("%s: failed to map clock registers\n", __func__);
> -		goto err;
> +		return NULL;
>  	}
>  
>  	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
>  	if (!clk_data)
> -		goto err;
> +		goto unmap_io;
>  
>  	clk_data->base = base;
>  	clk_table = kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL);
>  	if (!clk_table)
> -		goto err_data;
> +		goto free_clk_data;
>  
>  	clk_data->clk_data.clks = clk_table;
>  	clk_data->clk_data.clk_num = nr_clks;
>  	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
>  	return clk_data;
> -err_data:
> +free_clk_data:
>  	kfree(clk_data);
> -err:
> +unmap_io:
> +	iounmap(base);
>  	return NULL;
>  }
>  EXPORT_SYMBOL_GPL(hisi_clk_init);
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH V2] clk: hisilicon: Free clk_data and unmap region obtained by of_iomap
@ 2020-11-09 18:09 Dongjiu Geng
  2020-11-09 12:02 ` Dongjiu Geng
       [not found] ` <c6d2fe3b-3261-2c0f-f245-49bb5e63c1ed@web.de>
  0 siblings, 2 replies; 3+ messages in thread
From: Dongjiu Geng @ 2020-11-09 18:09 UTC (permalink / raw)
  To: mturquette, sboyd, linux-clk, linux-kernel, gengdongjiu

Free memory mapping and free clk_data, if clock initialization
is not successful.

Fixes: 75af25f581b1 ("clk: hisi: remove static variable")
Fixes: 62ac983b6141 ("clk: hisilicon: add hi3620_mmc_clks")
Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com>
---
 drivers/clk/hisilicon/clk-hi3620.c |  8 ++++++--
 drivers/clk/hisilicon/clk.c        | 11 ++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c
index a3d04c7c3da8..864d2ddfc73c 100644
--- a/drivers/clk/hisilicon/clk-hi3620.c
+++ b/drivers/clk/hisilicon/clk-hi3620.c
@@ -464,11 +464,11 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
 
 	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
 	if (WARN_ON(!clk_data))
-		return;
+		goto unmap_io;
 
 	clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL);
 	if (!clk_data->clks)
-		return;
+		goto free_clk_data;
 
 	for (i = 0; i < num; i++) {
 		struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i];
@@ -478,6 +478,10 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
 
 	clk_data->clk_num = num;
 	of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+free_clk_data:
+	kfree(clk_data);
+unmap_io:
+	iounmap(base);
 }
 
 CLK_OF_DECLARE(hi3620_mmc_clk, "hisilicon,hi3620-mmc-clock", hi3620_mmc_clk_init);
diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c
index 54d9fdc93599..da655683710f 100644
--- a/drivers/clk/hisilicon/clk.c
+++ b/drivers/clk/hisilicon/clk.c
@@ -65,25 +65,26 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np,
 	base = of_iomap(np, 0);
 	if (!base) {
 		pr_err("%s: failed to map clock registers\n", __func__);
-		goto err;
+		return NULL;
 	}
 
 	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
 	if (!clk_data)
-		goto err;
+		goto unmap_io;
 
 	clk_data->base = base;
 	clk_table = kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL);
 	if (!clk_table)
-		goto err_data;
+		goto free_clk_data;
 
 	clk_data->clk_data.clks = clk_table;
 	clk_data->clk_data.clk_num = nr_clks;
 	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data);
 	return clk_data;
-err_data:
+free_clk_data:
 	kfree(clk_data);
-err:
+unmap_io:
+	iounmap(base);
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(hisi_clk_init);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] clk: hisilicon: Free clk_data and unmap region obtained by of_iomap
       [not found] ` <c6d2fe3b-3261-2c0f-f245-49bb5e63c1ed@web.de>
@ 2020-11-10 11:58   ` Dongjiu Geng
  0 siblings, 0 replies; 3+ messages in thread
From: Dongjiu Geng @ 2020-11-10 11:58 UTC (permalink / raw)
  To: Markus Elfring, linux-clk
  Cc: linux-kernel, kernel-janitors, Michael Turquette, Stephen Boyd



On 2020/11/10 1:54, Markus Elfring wrote:
> …
>> +++ b/drivers/clk/hisilicon/clk-hi3620.c
> …
>> @@ -478,6 +478,10 @@ static void __init hi3620_mmc_clk_init(struct device_node *node)
>>
>>  	clk_data->clk_num = num;
>>  	of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
>> +free_clk_data:
>> +	kfree(clk_data);
> …
> 
> * Should any system resources be kept allocated if the execution
>   of this function implementation succeeded?
> 
> * How do you think about to add the statement “return;”
>   after the call of the function “of_clk_add_provider”?
> 
> * Should another return value be also checked here?

sure.

> 
>   See also:
>   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/clk/clk.c?id=f8394f232b1eab649ce2df5c5f15b0e528c92091#n4414
>   https://elixir.bootlin.com/linux/v5.10-rc2/source/drivers/clk/clk.c#L4414
> 
> * Would you like to use the function “of_clk_add_hw_provider” instead?

    How about we still use of_clk_add_provider()? It doesn't seem to make difference using of_clk_add_hw_provider().

> 
> Regards,
> Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-10 11:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 18:09 [PATCH V2] clk: hisilicon: Free clk_data and unmap region obtained by of_iomap Dongjiu Geng
2020-11-09 12:02 ` Dongjiu Geng
     [not found] ` <c6d2fe3b-3261-2c0f-f245-49bb5e63c1ed@web.de>
2020-11-10 11:58   ` [PATCH v2] " Dongjiu Geng

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).