linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/clk: convert VL struct to struct_size
@ 2019-09-27 18:51 Stephen Kitt
  2019-10-02 19:20 ` Gustavo A. R. Silva
  2019-11-08 16:37 ` Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Kitt @ 2019-09-27 18:51 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Nicolas Ferre, Paul Burton,
	Paul Cercueil, Masahiro Yamada
  Cc: linux-clk, linux-kernel, Stephen Kitt

There are a few manually-calculated variable-length struct allocations
left, this converts them to use struct_size.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 drivers/clk/at91/sckc.c                     | 3 +--
 drivers/clk/imgtec/clk-boston.c             | 3 +--
 drivers/clk/ingenic/tcu.c                   | 3 +--
 drivers/clk/mvebu/ap-cpu-clk.c              | 4 ++--
 drivers/clk/mvebu/cp110-system-controller.c | 4 ++--
 drivers/clk/samsung/clk.c                   | 3 +--
 drivers/clk/uniphier/clk-uniphier-core.c    | 3 +--
 7 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/clk/at91/sckc.c b/drivers/clk/at91/sckc.c
index 9bfe9a28294a..5ad6180449cb 100644
--- a/drivers/clk/at91/sckc.c
+++ b/drivers/clk/at91/sckc.c
@@ -478,8 +478,7 @@ static void __init of_sam9x60_sckc_setup(struct device_node *np)
 	if (IS_ERR(slow_osc))
 		goto unregister_slow_rc;
 
-	clk_data = kzalloc(sizeof(*clk_data) + (2 * sizeof(struct clk_hw *)),
-			   GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL);
 	if (!clk_data)
 		goto unregister_slow_osc;
 
diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c
index 33ab4ff61165..b00cbd045af5 100644
--- a/drivers/clk/imgtec/clk-boston.c
+++ b/drivers/clk/imgtec/clk-boston.c
@@ -58,8 +58,7 @@ static void __init clk_boston_setup(struct device_node *np)
 	cpu_div = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_CLK1DIV);
 	cpu_freq = mult_frac(in_freq, mul, cpu_div);
 
-	onecell = kzalloc(sizeof(*onecell) +
-			  (BOSTON_CLK_COUNT * sizeof(struct clk_hw *)),
+	onecell = kzalloc(struct_size(onecell, hws, BOSTON_CLK_COUNT),
 			  GFP_KERNEL);
 	if (!onecell)
 		return;
diff --git a/drivers/clk/ingenic/tcu.c b/drivers/clk/ingenic/tcu.c
index a1a5f9cb439e..ad7daa494fd4 100644
--- a/drivers/clk/ingenic/tcu.c
+++ b/drivers/clk/ingenic/tcu.c
@@ -358,8 +358,7 @@ static int __init ingenic_tcu_probe(struct device_node *np)
 		}
 	}
 
-	tcu->clocks = kzalloc(sizeof(*tcu->clocks) +
-			      sizeof(*tcu->clocks->hws) * TCU_CLK_COUNT,
+	tcu->clocks = kzalloc(struct_size(tcu->clocks, hws, TCU_CLK_COUNT),
 			      GFP_KERNEL);
 	if (!tcu->clocks) {
 		ret = -ENOMEM;
diff --git a/drivers/clk/mvebu/ap-cpu-clk.c b/drivers/clk/mvebu/ap-cpu-clk.c
index af5e5acad370..6b394302c76a 100644
--- a/drivers/clk/mvebu/ap-cpu-clk.c
+++ b/drivers/clk/mvebu/ap-cpu-clk.c
@@ -274,8 +274,8 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
 	if (!ap_cpu_clk)
 		return -ENOMEM;
 
-	ap_cpu_data = devm_kzalloc(dev, sizeof(*ap_cpu_data) +
-				sizeof(struct clk_hw *) * nclusters,
+	ap_cpu_data = devm_kzalloc(dev, struct_size(ap_cpu_data, hws,
+						    nclusters),
 				GFP_KERNEL);
 	if (!ap_cpu_data)
 		return -ENOMEM;
diff --git a/drivers/clk/mvebu/cp110-system-controller.c b/drivers/clk/mvebu/cp110-system-controller.c
index 808463276145..84c8900542e4 100644
--- a/drivers/clk/mvebu/cp110-system-controller.c
+++ b/drivers/clk/mvebu/cp110-system-controller.c
@@ -235,8 +235,8 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
-	cp110_clk_data = devm_kzalloc(dev, sizeof(*cp110_clk_data) +
-				      sizeof(struct clk_hw *) * CP110_CLK_NUM,
+	cp110_clk_data = devm_kzalloc(dev, struct_size(cp110_clk_data, hws,
+						       CP110_CLK_NUM),
 				      GFP_KERNEL);
 	if (!cp110_clk_data)
 		return -ENOMEM;
diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c
index e544a38106dd..dad31308c071 100644
--- a/drivers/clk/samsung/clk.c
+++ b/drivers/clk/samsung/clk.c
@@ -60,8 +60,7 @@ struct samsung_clk_provider *__init samsung_clk_init(struct device_node *np,
 	struct samsung_clk_provider *ctx;
 	int i;
 
-	ctx = kzalloc(sizeof(struct samsung_clk_provider) +
-		      sizeof(*ctx->clk_data.hws) * nr_clks, GFP_KERNEL);
+	ctx = kzalloc(struct_size(ctx, clk_data.hws, nr_clks), GFP_KERNEL);
 	if (!ctx)
 		panic("could not allocate clock provider context.\n");
 
diff --git a/drivers/clk/uniphier/clk-uniphier-core.c b/drivers/clk/uniphier/clk-uniphier-core.c
index c6aaca73cf86..12380236d7ab 100644
--- a/drivers/clk/uniphier/clk-uniphier-core.c
+++ b/drivers/clk/uniphier/clk-uniphier-core.c
@@ -64,8 +64,7 @@ static int uniphier_clk_probe(struct platform_device *pdev)
 	for (p = data; p->name; p++)
 		clk_num = max(clk_num, p->idx + 1);
 
-	hw_data = devm_kzalloc(dev,
-			sizeof(*hw_data) + clk_num * sizeof(struct clk_hw *),
+	hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, clk_num),
 			GFP_KERNEL);
 	if (!hw_data)
 		return -ENOMEM;
-- 
2.20.1


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

* Re: [PATCH] drivers/clk: convert VL struct to struct_size
  2019-09-27 18:51 [PATCH] drivers/clk: convert VL struct to struct_size Stephen Kitt
@ 2019-10-02 19:20 ` Gustavo A. R. Silva
       [not found]   ` <20191107225002.1520821D7F@mail.kernel.org>
  2019-11-08 16:37 ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-10-02 19:20 UTC (permalink / raw)
  To: Stephen Kitt, Michael Turquette, Stephen Boyd, Nicolas Ferre,
	Paul Burton, Paul Cercueil, Masahiro Yamada
  Cc: linux-clk, linux-kernel



On 9/27/19 13:51, Stephen Kitt wrote:
> There are a few manually-calculated variable-length struct allocations
> left, this converts them to use struct_size.
> 

How did you find this?

Please, mention the tool you used to find this in the commit log. With that
you can add my

Acked-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Thanks
--
Gustavo

> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---
>  drivers/clk/at91/sckc.c                     | 3 +--
>  drivers/clk/imgtec/clk-boston.c             | 3 +--
>  drivers/clk/ingenic/tcu.c                   | 3 +--
>  drivers/clk/mvebu/ap-cpu-clk.c              | 4 ++--
>  drivers/clk/mvebu/cp110-system-controller.c | 4 ++--
>  drivers/clk/samsung/clk.c                   | 3 +--
>  drivers/clk/uniphier/clk-uniphier-core.c    | 3 +--
>  7 files changed, 9 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/clk/at91/sckc.c b/drivers/clk/at91/sckc.c
> index 9bfe9a28294a..5ad6180449cb 100644
> --- a/drivers/clk/at91/sckc.c
> +++ b/drivers/clk/at91/sckc.c
> @@ -478,8 +478,7 @@ static void __init of_sam9x60_sckc_setup(struct device_node *np)
>  	if (IS_ERR(slow_osc))
>  		goto unregister_slow_rc;
>  
> -	clk_data = kzalloc(sizeof(*clk_data) + (2 * sizeof(struct clk_hw *)),
> -			   GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL);
>  	if (!clk_data)
>  		goto unregister_slow_osc;
>  
> diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c
> index 33ab4ff61165..b00cbd045af5 100644
> --- a/drivers/clk/imgtec/clk-boston.c
> +++ b/drivers/clk/imgtec/clk-boston.c
> @@ -58,8 +58,7 @@ static void __init clk_boston_setup(struct device_node *np)
>  	cpu_div = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_CLK1DIV);
>  	cpu_freq = mult_frac(in_freq, mul, cpu_div);
>  
> -	onecell = kzalloc(sizeof(*onecell) +
> -			  (BOSTON_CLK_COUNT * sizeof(struct clk_hw *)),
> +	onecell = kzalloc(struct_size(onecell, hws, BOSTON_CLK_COUNT),
>  			  GFP_KERNEL);
>  	if (!onecell)
>  		return;
> diff --git a/drivers/clk/ingenic/tcu.c b/drivers/clk/ingenic/tcu.c
> index a1a5f9cb439e..ad7daa494fd4 100644
> --- a/drivers/clk/ingenic/tcu.c
> +++ b/drivers/clk/ingenic/tcu.c
> @@ -358,8 +358,7 @@ static int __init ingenic_tcu_probe(struct device_node *np)
>  		}
>  	}
>  
> -	tcu->clocks = kzalloc(sizeof(*tcu->clocks) +
> -			      sizeof(*tcu->clocks->hws) * TCU_CLK_COUNT,
> +	tcu->clocks = kzalloc(struct_size(tcu->clocks, hws, TCU_CLK_COUNT),
>  			      GFP_KERNEL);
>  	if (!tcu->clocks) {
>  		ret = -ENOMEM;
> diff --git a/drivers/clk/mvebu/ap-cpu-clk.c b/drivers/clk/mvebu/ap-cpu-clk.c
> index af5e5acad370..6b394302c76a 100644
> --- a/drivers/clk/mvebu/ap-cpu-clk.c
> +++ b/drivers/clk/mvebu/ap-cpu-clk.c
> @@ -274,8 +274,8 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
>  	if (!ap_cpu_clk)
>  		return -ENOMEM;
>  
> -	ap_cpu_data = devm_kzalloc(dev, sizeof(*ap_cpu_data) +
> -				sizeof(struct clk_hw *) * nclusters,
> +	ap_cpu_data = devm_kzalloc(dev, struct_size(ap_cpu_data, hws,
> +						    nclusters),
>  				GFP_KERNEL);
>  	if (!ap_cpu_data)
>  		return -ENOMEM;
> diff --git a/drivers/clk/mvebu/cp110-system-controller.c b/drivers/clk/mvebu/cp110-system-controller.c
> index 808463276145..84c8900542e4 100644
> --- a/drivers/clk/mvebu/cp110-system-controller.c
> +++ b/drivers/clk/mvebu/cp110-system-controller.c
> @@ -235,8 +235,8 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
>  	if (ret)
>  		return ret;
>  
> -	cp110_clk_data = devm_kzalloc(dev, sizeof(*cp110_clk_data) +
> -				      sizeof(struct clk_hw *) * CP110_CLK_NUM,
> +	cp110_clk_data = devm_kzalloc(dev, struct_size(cp110_clk_data, hws,
> +						       CP110_CLK_NUM),
>  				      GFP_KERNEL);
>  	if (!cp110_clk_data)
>  		return -ENOMEM;
> diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c
> index e544a38106dd..dad31308c071 100644
> --- a/drivers/clk/samsung/clk.c
> +++ b/drivers/clk/samsung/clk.c
> @@ -60,8 +60,7 @@ struct samsung_clk_provider *__init samsung_clk_init(struct device_node *np,
>  	struct samsung_clk_provider *ctx;
>  	int i;
>  
> -	ctx = kzalloc(sizeof(struct samsung_clk_provider) +
> -		      sizeof(*ctx->clk_data.hws) * nr_clks, GFP_KERNEL);
> +	ctx = kzalloc(struct_size(ctx, clk_data.hws, nr_clks), GFP_KERNEL);
>  	if (!ctx)
>  		panic("could not allocate clock provider context.\n");
>  
> diff --git a/drivers/clk/uniphier/clk-uniphier-core.c b/drivers/clk/uniphier/clk-uniphier-core.c
> index c6aaca73cf86..12380236d7ab 100644
> --- a/drivers/clk/uniphier/clk-uniphier-core.c
> +++ b/drivers/clk/uniphier/clk-uniphier-core.c
> @@ -64,8 +64,7 @@ static int uniphier_clk_probe(struct platform_device *pdev)
>  	for (p = data; p->name; p++)
>  		clk_num = max(clk_num, p->idx + 1);
>  
> -	hw_data = devm_kzalloc(dev,
> -			sizeof(*hw_data) + clk_num * sizeof(struct clk_hw *),
> +	hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, clk_num),
>  			GFP_KERNEL);
>  	if (!hw_data)
>  		return -ENOMEM;
> 

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

* Re: [PATCH] drivers/clk: convert VL struct to struct_size
       [not found]   ` <20191107225002.1520821D7F@mail.kernel.org>
@ 2019-11-08 12:34     ` Stephen Kitt
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Kitt @ 2019-11-08 12:34 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Gustavo A. R. Silva, Masahiro Yamada, Michael Turquette,
	Nicolas Ferre, Paul Burton, Paul Cercueil, linux-clk,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 975 bytes --]

On Thu, 07 Nov 2019 14:50:01 -0800, Stephen Boyd <sboyd@kernel.org> wrote:
> Quoting Gustavo A. R. Silva (2019-10-02 12:20:28)
> > On 9/27/19 13:51, Stephen Kitt wrote:  
> > > There are a few manually-calculated variable-length struct allocations
> > > left, this converts them to use struct_size.
> > 
> > How did you find this?
> > 
> > Please, mention the tool you used to find this in the commit log. With
> > that you can add my
> > 
> > Acked-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> 
> Any answer? I'm tempted to just apply the patch anyway.

Sorry, I hadn’t seen Gustavo’s email!

I didn’t use anything particularly fancy to find these, my history says

	git grep -A1 'kzalloc.*sizeof[^_].*+'

and manual review. I noticed that clk/ had a number of hits, but also commits
to switch to struct_size so I reckoned it was worth pursuing the exercise
there.

Is it worth adding that to the commit message?

Regards,

Stephen

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] drivers/clk: convert VL struct to struct_size
  2019-09-27 18:51 [PATCH] drivers/clk: convert VL struct to struct_size Stephen Kitt
  2019-10-02 19:20 ` Gustavo A. R. Silva
@ 2019-11-08 16:37 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2019-11-08 16:37 UTC (permalink / raw)
  To: Masahiro Yamada, Michael Turquette, Nicolas Ferre, Paul Burton,
	Paul Cercueil, Stephen Kitt
  Cc: linux-clk, linux-kernel, Stephen Kitt

Quoting Stephen Kitt (2019-09-27 11:51:10)
> There are a few manually-calculated variable-length struct allocations
> left, this converts them to use struct_size.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---

Applied to clk-next


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

end of thread, other threads:[~2019-11-08 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27 18:51 [PATCH] drivers/clk: convert VL struct to struct_size Stephen Kitt
2019-10-02 19:20 ` Gustavo A. R. Silva
     [not found]   ` <20191107225002.1520821D7F@mail.kernel.org>
2019-11-08 12:34     ` Stephen Kitt
2019-11-08 16:37 ` Stephen Boyd

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