net/switchdev: use struct_size over open coded arithmetic
Subsystems (3)
PATCH v2 1/1 net/switchdev: use struct_size over open coded arithmetic
From: Minghao Chi (CGEL ZTE) <[email protected]>
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.
--- net/switchdev/switchdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/switchdev/switchdev.c +1 -1
@@ -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;
Signature · 1 line
2.25.1
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 11 lines · On Thu, 10 Feb 2022 06:10:08 +0000 you wrote:
From: Minghao Chi (CGEL ZTE) <[email protected]>
Replace zero-length array with flexible-array member and make use of the
struct_size()helper inkmalloc(). 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html