Message ID | 20220210061008.1608468-1-chi.minghao@zte.com.cn (mailing list archive) |
---|---|
State | Accepted |
Commit | d8c2858181ccf0ca506b75ffe1ffab25a090d0e4 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [V2] net/switchdev: use struct_size over open coded arithmetic | expand |
Hello: This patch was applied to netdev/net-next.git (master) by David S. Miller <davem@davemloft.net>: On Thu, 10 Feb 2022 06:10:08 +0000 you wrote: > From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn> > > 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[]; > }; > > [...] Here is the summary with links: - [V2] net/switchdev: use struct_size over open coded arithmetic https://git.kernel.org/netdev/net-next/c/d8c2858181cc You are awesome, thank you!
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index b62565278fac..12e6b4146bfb 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c @@ -85,7 +85,7 @@ static int switchdev_deferred_enqueue(struct net_device *dev, { struct switchdev_deferred_item *dfitem; - dfitem = kmalloc(sizeof(*dfitem) + data_len, GFP_ATOMIC); + dfitem = kmalloc(struct_size(dfitem, data, data_len), GFP_ATOMIC); if (!dfitem) return -ENOMEM; dfitem->dev = dev;