All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: sched: cls_u32: use struct_size() helper
@ 2019-05-01 16:23 Gustavo A. R. Silva
  2019-05-04  4:47 ` David Miller
  2019-05-23 23:22 ` Gustavo A. R. Silva
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-05-01 16:23 UTC (permalink / raw)
  To: Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S. Miller
  Cc: netdev, linux-kernel, Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes, in particular in the
context in which this code is being used.

So, replace code of the following form:

sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)

with:

struct_size(s, keys, s->nkeys)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 net/sched/cls_u32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index 04e9ef088535..4b8710a266cc 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -847,7 +847,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
 	/* Similarly success statistics must be moved as pointers */
 	new->pcpu_success = n->pcpu_success;
 #endif
-	memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
+	memcpy(&new->sel, s, struct_size(s, keys, s->nkeys));
 
 	if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) {
 		kfree(new);
-- 
2.21.0


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

* Re: [PATCH net-next] net: sched: cls_u32: use struct_size() helper
  2019-05-01 16:23 [PATCH net-next] net: sched: cls_u32: use struct_size() helper Gustavo A. R. Silva
@ 2019-05-04  4:47 ` David Miller
  2019-05-23 23:22 ` Gustavo A. R. Silva
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2019-05-04  4:47 UTC (permalink / raw)
  To: gustavo; +Cc: jhs, xiyou.wangcong, jiri, netdev, linux-kernel

From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Date: Wed, 1 May 2019 11:23:15 -0500

> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes, in particular in the
> context in which this code is being used.
> 
> So, replace code of the following form:
> 
> sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)
> 
> with:
> 
> struct_size(s, keys, s->nkeys)
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Applied.

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

* Re: [PATCH net-next] net: sched: cls_u32: use struct_size() helper
  2019-05-01 16:23 [PATCH net-next] net: sched: cls_u32: use struct_size() helper Gustavo A. R. Silva
  2019-05-04  4:47 ` David Miller
@ 2019-05-23 23:22 ` Gustavo A. R. Silva
  2019-05-23 23:25   ` Gustavo A. R. Silva
  1 sibling, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-05-23 23:22 UTC (permalink / raw)
  To: Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S. Miller
  Cc: netdev, linux-kernel

Hi all,

Friendly ping:

Who can take this?

Thanks
--
Gustavo

On 5/1/19 11:23 AM, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes, in particular in the
> context in which this code is being used.
> 
> So, replace code of the following form:
> 
> sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)
> 
> with:
> 
> struct_size(s, keys, s->nkeys)
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  net/sched/cls_u32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
> index 04e9ef088535..4b8710a266cc 100644
> --- a/net/sched/cls_u32.c
> +++ b/net/sched/cls_u32.c
> @@ -847,7 +847,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
>  	/* Similarly success statistics must be moved as pointers */
>  	new->pcpu_success = n->pcpu_success;
>  #endif
> -	memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
> +	memcpy(&new->sel, s, struct_size(s, keys, s->nkeys));
>  
>  	if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) {
>  		kfree(new);
> 

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

* Re: [PATCH net-next] net: sched: cls_u32: use struct_size() helper
  2019-05-23 23:22 ` Gustavo A. R. Silva
@ 2019-05-23 23:25   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-05-23 23:25 UTC (permalink / raw)
  To: Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S. Miller
  Cc: netdev, linux-kernel

Hi,

Sorry about the noise. I just noticed that Dave took this a while ago.

Thanks
--

On 5/23/19 6:22 PM, Gustavo A. R. Silva wrote:
> Hi all,
> 
> Friendly ping:
> 
> Who can take this?
> 
> Thanks
> --
> Gustavo
> 
> On 5/1/19 11:23 AM, Gustavo A. R. Silva wrote:
>> Make use of the struct_size() helper instead of an open-coded version
>> in order to avoid any potential type mistakes, in particular in the
>> context in which this code is being used.
>>
>> So, replace code of the following form:
>>
>> sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)
>>
>> with:
>>
>> struct_size(s, keys, s->nkeys)
>>
>> This code was detected with the help of Coccinelle.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>  net/sched/cls_u32.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
>> index 04e9ef088535..4b8710a266cc 100644
>> --- a/net/sched/cls_u32.c
>> +++ b/net/sched/cls_u32.c
>> @@ -847,7 +847,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
>>  	/* Similarly success statistics must be moved as pointers */
>>  	new->pcpu_success = n->pcpu_success;
>>  #endif
>> -	memcpy(&new->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key));
>> +	memcpy(&new->sel, s, struct_size(s, keys, s->nkeys));
>>  
>>  	if (tcf_exts_init(&new->exts, net, TCA_U32_ACT, TCA_U32_POLICE)) {
>>  		kfree(new);
>>

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

end of thread, other threads:[~2019-05-23 23:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-01 16:23 [PATCH net-next] net: sched: cls_u32: use struct_size() helper Gustavo A. R. Silva
2019-05-04  4:47 ` David Miller
2019-05-23 23:22 ` Gustavo A. R. Silva
2019-05-23 23:25   ` 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.