net: sched: cls_u32: use struct_size() helper
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 1 May 2019 16:23:15 +0000 (11:23 -0500)
committerDavid S. Miller <davem@davemloft.net>
Sat, 4 May 2019 04:46:27 +0000 (00:46 -0400)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/cls_u32.c

index 04e9ef088535af5928dc140f038e9745f053348b..4b8710a266cca9a06e7390f7f36bd226b1bc9cb9 100644 (file)
@@ -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);