All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
@ 2018-12-24  6:40 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2018-12-24  6:40 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Michael Turquette, Stephen Boyd
  Cc: linux-arm-kernel, linux-clk, linux-kernel, Gustavo A. R. Silva

One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/clk/imx/clk-imx7ulp.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/imx/clk-imx7ulp.c b/drivers/clk/imx/clk-imx7ulp.c
index 4e18f629f823..ce306631e844 100644
--- a/drivers/clk/imx/clk-imx7ulp.c
+++ b/drivers/clk/imx/clk-imx7ulp.c
@@ -48,8 +48,8 @@ static void __init imx7ulp_clk_scg1_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_SCG1_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SCG1_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
@@ -136,8 +136,8 @@ static void __init imx7ulp_clk_pcc2_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_PCC2_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC2_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
@@ -183,8 +183,8 @@ static void __init imx7ulp_clk_pcc3_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_PCC3_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC3_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
@@ -228,8 +228,8 @@ static void __init imx7ulp_clk_smc1_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_SMC1_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SMC1_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
-- 
2.20.1


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

* [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
@ 2018-12-24  6:40 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2018-12-24  6:40 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Michael Turquette, Stephen Boyd
  Cc: Gustavo A. R. Silva, linux-clk, linux-arm-kernel, linux-kernel

One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

This issue was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/clk/imx/clk-imx7ulp.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/imx/clk-imx7ulp.c b/drivers/clk/imx/clk-imx7ulp.c
index 4e18f629f823..ce306631e844 100644
--- a/drivers/clk/imx/clk-imx7ulp.c
+++ b/drivers/clk/imx/clk-imx7ulp.c
@@ -48,8 +48,8 @@ static void __init imx7ulp_clk_scg1_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_SCG1_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SCG1_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
@@ -136,8 +136,8 @@ static void __init imx7ulp_clk_pcc2_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_PCC2_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC2_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
@@ -183,8 +183,8 @@ static void __init imx7ulp_clk_pcc3_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_PCC3_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC3_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
@@ -228,8 +228,8 @@ static void __init imx7ulp_clk_smc1_init(struct device_node *np)
 	struct clk_hw **clks;
 	void __iomem *base;
 
-	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
-			   IMX7ULP_CLK_SMC1_END, GFP_KERNEL);
+	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SMC1_END),
+			   GFP_KERNEL);
 	if (!clk_data)
 		return;
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
  2018-12-24  6:40 ` Gustavo A. R. Silva
@ 2018-12-24  9:03   ` Aisheng Dong
  -1 siblings, 0 replies; 10+ messages in thread
From: Aisheng Dong @ 2018-12-24  9:03 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx,
	Michael Turquette, Stephen Boyd
  Cc: linux-arm-kernel, linux-clk, linux-kernel

> -----Original Message-----
> From: Gustavo A. R. Silva [mailto:gustavo@embeddedor.com]
> Sent: Monday, December 24, 2018 2:40 PM
> 
> One of the more common cases of allocation size calculations is finding the
> size of a structure that has a zero-sized array at the end, along with memory
> for some number of elements for that array. For example:
> 
> struct foo {
>     int stuff;
>     void *entry[];
> };
> 
> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
> 
> Instead of leaving these open-coded and prone to type mistakes, we can now
> use the new struct_size() helper:
> 
> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

Regards
Dong Aisheng

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

* RE: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
@ 2018-12-24  9:03   ` Aisheng Dong
  0 siblings, 0 replies; 10+ messages in thread
From: Aisheng Dong @ 2018-12-24  9:03 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx,
	Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-arm-kernel, linux-kernel

> -----Original Message-----
> From: Gustavo A. R. Silva [mailto:gustavo@embeddedor.com]
> Sent: Monday, December 24, 2018 2:40 PM
> 
> One of the more common cases of allocation size calculations is finding the
> size of a structure that has a zero-sized array at the end, along with memory
> for some number of elements for that array. For example:
> 
> struct foo {
>     int stuff;
>     void *entry[];
> };
> 
> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
> 
> Instead of leaving these open-coded and prone to type mistakes, we can now
> use the new struct_size() helper:
> 
> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>

Regards
Dong Aisheng

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
  2018-12-24  6:40 ` Gustavo A. R. Silva
@ 2019-01-14 16:44   ` Gustavo A. R. Silva
  -1 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2019-01-14 16:44 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Michael Turquette, Stephen Boyd
  Cc: linux-arm-kernel, linux-clk, linux-kernel

Hi,

Friendly ping:

Who can take this?

Thanks
--
Gustavo

On 12/24/18 12:40 AM, Gustavo A. R. Silva wrote:
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
> 
> struct foo {
>      int stuff;
>      void *entry[];
> };
> 
> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
> 
> Instead of leaving these open-coded and prone to type mistakes, we can
> now use the new struct_size() helper:
> 
> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>   drivers/clk/imx/clk-imx7ulp.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/clk/imx/clk-imx7ulp.c b/drivers/clk/imx/clk-imx7ulp.c
> index 4e18f629f823..ce306631e844 100644
> --- a/drivers/clk/imx/clk-imx7ulp.c
> +++ b/drivers/clk/imx/clk-imx7ulp.c
> @@ -48,8 +48,8 @@ static void __init imx7ulp_clk_scg1_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_SCG1_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SCG1_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> @@ -136,8 +136,8 @@ static void __init imx7ulp_clk_pcc2_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_PCC2_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC2_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> @@ -183,8 +183,8 @@ static void __init imx7ulp_clk_pcc3_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_PCC3_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC3_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> @@ -228,8 +228,8 @@ static void __init imx7ulp_clk_smc1_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_SMC1_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SMC1_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> 

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

* Re: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
@ 2019-01-14 16:44   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2019-01-14 16:44 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Michael Turquette, Stephen Boyd
  Cc: linux-clk, linux-arm-kernel, linux-kernel

Hi,

Friendly ping:

Who can take this?

Thanks
--
Gustavo

On 12/24/18 12:40 AM, Gustavo A. R. Silva wrote:
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
> 
> struct foo {
>      int stuff;
>      void *entry[];
> };
> 
> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
> 
> Instead of leaving these open-coded and prone to type mistakes, we can
> now use the new struct_size() helper:
> 
> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>   drivers/clk/imx/clk-imx7ulp.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/clk/imx/clk-imx7ulp.c b/drivers/clk/imx/clk-imx7ulp.c
> index 4e18f629f823..ce306631e844 100644
> --- a/drivers/clk/imx/clk-imx7ulp.c
> +++ b/drivers/clk/imx/clk-imx7ulp.c
> @@ -48,8 +48,8 @@ static void __init imx7ulp_clk_scg1_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_SCG1_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SCG1_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> @@ -136,8 +136,8 @@ static void __init imx7ulp_clk_pcc2_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_PCC2_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC2_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> @@ -183,8 +183,8 @@ static void __init imx7ulp_clk_pcc3_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_PCC3_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC3_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> @@ -228,8 +228,8 @@ static void __init imx7ulp_clk_smc1_init(struct device_node *np)
>   	struct clk_hw **clks;
>   	void __iomem *base;
>   
> -	clk_data = kzalloc(sizeof(*clk_data) + sizeof(*clk_data->hws) *
> -			   IMX7ULP_CLK_SMC1_END, GFP_KERNEL);
> +	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SMC1_END),
> +			   GFP_KERNEL);
>   	if (!clk_data)
>   		return;
>   
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
  2018-12-24  6:40 ` Gustavo A. R. Silva
@ 2019-01-24 19:37   ` Stephen Boyd
  -1 siblings, 0 replies; 10+ messages in thread
From: Stephen Boyd @ 2019-01-24 19:37 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Fabio Estevam, Michael Turquette,
	NXP Linux Team, Pengutronix Kernel Team, Sascha Hauer, Shawn Guo
  Cc: linux-arm-kernel, linux-clk, linux-kernel, Gustavo A. R. Silva

Quoting Gustavo A. R. Silva (2018-12-23 22:40:25)
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
> 
> struct foo {
>     int stuff;
>     void *entry[];
> };
> 
> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
> 
> Instead of leaving these open-coded and prone to type mistakes, we can
> now use the new struct_size() helper:
> 
> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---

Applied to clk-next


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

* Re: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
@ 2019-01-24 19:37   ` Stephen Boyd
  0 siblings, 0 replies; 10+ messages in thread
From: Stephen Boyd @ 2019-01-24 19:37 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Fabio Estevam, Michael Turquette,
	NXP Linux Team, Pengutronix Kernel Team, Sascha Hauer, Shawn Guo
  Cc: Gustavo A. R. Silva, linux-clk, linux-arm-kernel, linux-kernel

Quoting Gustavo A. R. Silva (2018-12-23 22:40:25)
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
> 
> struct foo {
>     int stuff;
>     void *entry[];
> };
> 
> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
> 
> Instead of leaving these open-coded and prone to type mistakes, we can
> now use the new struct_size() helper:
> 
> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
> 
> This issue was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---

Applied to clk-next


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
  2019-01-24 19:37   ` Stephen Boyd
@ 2019-01-24 19:39     ` Gustavo A. R. Silva
  -1 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2019-01-24 19:39 UTC (permalink / raw)
  To: Stephen Boyd, Fabio Estevam, Michael Turquette, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo
  Cc: linux-arm-kernel, linux-clk, linux-kernel



On 1/24/19 1:37 PM, Stephen Boyd wrote:
> Quoting Gustavo A. R. Silva (2018-12-23 22:40:25)
>> One of the more common cases of allocation size calculations is finding
>> the size of a structure that has a zero-sized array at the end, along
>> with memory for some number of elements for that array. For example:
>>
>> struct foo {
>>     int stuff;
>>     void *entry[];
>> };
>>
>> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
>>
>> Instead of leaving these open-coded and prone to type mistakes, we can
>> now use the new struct_size() helper:
>>
>> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
>>
>> This issue was detected with the help of Coccinelle.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
> 
> Applied to clk-next
> 

Thanks, Stephen.

--
Gustavo

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

* Re: [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc()
@ 2019-01-24 19:39     ` Gustavo A. R. Silva
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2019-01-24 19:39 UTC (permalink / raw)
  To: Stephen Boyd, Fabio Estevam, Michael Turquette, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo
  Cc: linux-clk, linux-arm-kernel, linux-kernel



On 1/24/19 1:37 PM, Stephen Boyd wrote:
> Quoting Gustavo A. R. Silva (2018-12-23 22:40:25)
>> One of the more common cases of allocation size calculations is finding
>> the size of a structure that has a zero-sized array at the end, along
>> with memory for some number of elements for that array. For example:
>>
>> struct foo {
>>     int stuff;
>>     void *entry[];
>> };
>>
>> instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);
>>
>> Instead of leaving these open-coded and prone to type mistakes, we can
>> now use the new struct_size() helper:
>>
>> instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
>>
>> This issue was detected with the help of Coccinelle.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
> 
> Applied to clk-next
> 

Thanks, Stephen.

--
Gustavo

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2019-01-24 20:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-24  6:40 [PATCH] clk: imx: imx7ulp: use struct_size() in kzalloc() Gustavo A. R. Silva
2018-12-24  6:40 ` Gustavo A. R. Silva
2018-12-24  9:03 ` Aisheng Dong
2018-12-24  9:03   ` Aisheng Dong
2019-01-14 16:44 ` Gustavo A. R. Silva
2019-01-14 16:44   ` Gustavo A. R. Silva
2019-01-24 19:37 ` Stephen Boyd
2019-01-24 19:37   ` Stephen Boyd
2019-01-24 19:39   ` Gustavo A. R. Silva
2019-01-24 19:39     ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.