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

net/switchdev: use struct_size over open coded arithmetic

Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kmalloc(). For example:

struct switchdev_deferred_item {
...
unsigned long data[];
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Minghao Chi (CGEL ZTE) and committed by
David S. Miller
d8c28581 dc513a40

+1 -1
+1 -1
net/switchdev/switchdev.c
··· 85 85 { 86 86 struct switchdev_deferred_item *dfitem; 87 87 88 - dfitem = kmalloc(sizeof(*dfitem) + data_len, GFP_ATOMIC); 88 + dfitem = kmalloc(struct_size(dfitem, data, data_len), GFP_ATOMIC); 89 89 if (!dfitem) 90 90 return -ENOMEM; 91 91 dfitem->dev = dev;