Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <gustavoars@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Gustavo A. R. Silva and committed by
David S. Miller
c5eb179e 11a33de2

+1 -3
+1 -3
net/sched/cls_u32.c
··· 796 796 struct tc_u32_sel *s = &n->sel; 797 797 struct tc_u_knode *new; 798 798 799 - new = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), 800 - GFP_KERNEL); 801 - 799 + new = kzalloc(struct_size(new, sel.keys, s->nkeys), GFP_KERNEL); 802 800 if (!new) 803 801 return NULL; 804 802