@@ -25,6 +25,7 @@
#include <linux/bug.h>
#include <linux/delay.h>
#include <linux/atomic.h>
+#include <linux/overflow.h>
#include <linux/prefetch.h>
#include <asm/cache.h>
#include <asm/byteorder.h>
@@ -2668,7 +2669,7 @@ void dev_net_set(struct net_device *dev, struct net *net)
*/
static inline void *netdev_priv(const struct net_device *dev)
{
- return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
+ return struct_data_pointer(dev, NETDEV_ALIGN);
}
/* Set the sysfs physical device reference for the network logical device
@@ -10859,12 +10859,12 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
return NULL;
}
- alloc_size = sizeof(struct net_device);
- if (sizeof_priv) {
+ if (sizeof_priv)
/* ensure 32-byte alignment of private area */
- alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
- alloc_size += sizeof_priv;
- }
+ alloc_size = struct_size_with_data(p, NETDEV_ALIGN, sizeof_priv);
+ else
+ alloc_size = sizeof(struct net_device);
+
/* ensure 32-byte alignment of whole construct */
alloc_size += NETDEV_ALIGN - 1;
We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in alloc_netdev_mqs() and netdev_priv(). Do it so. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- include/linux/netdevice.h | 3 ++- net/core/dev.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-)