From: Gustavo A. R. Silva Date: Thu, 18 Jun 2020 14:53:42 +0000 (-0500) Subject: net/sched: cls_u32: Use struct_size() in kzalloc() X-Git-Tag: v5.10.7~1943^2~472 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5eb179edd8a169949b1fb153ecfd04649a71c8d;p=platform%2Fkernel%2Flinux-rpi.git net/sched: cls_u32: Use struct_size() in kzalloc() Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva Signed-off-by: David S. Miller --- diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index e15ff33..771b068 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -796,9 +796,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp, struct tc_u32_sel *s = &n->sel; struct tc_u_knode *new; - new = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), - GFP_KERNEL); - + new = kzalloc(struct_size(new, sel.keys, s->nkeys), GFP_KERNEL); if (!new) return NULL;