[PATCH] net: ALIGN/PTR_ALIGN cleanup in alloc_netdev_mq()/netdev_priv()

Previous thread: netfilter 02/04: nf_ct_dccp: add missing DCCP protocol changes in event cache by Patrick McHardy on Wednesday, May 27, 2009 - 7:35 am. (6 messages)

Next thread: (no subject) by ul on Wednesday, May 27, 2009 - 7:53 am. (1 message)
From: Eric Dumazet
Date: Wednesday, May 27, 2009 - 7:42 am

Use ALIGN() and PTR_ALIGN() macros instead of handcoding them.

Get rid of NETDEV_ALIGN_CONST ugly define

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
 include/linux/netdevice.h |    5 +----
 net/core/dev.c            |    9 ++++-----
 net/mac80211/main.c       |    8 ++------
 3 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 371ece5..14efce3 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -905,7 +905,6 @@ struct net_device
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 
 #define	NETDEV_ALIGN		32
-#define	NETDEV_ALIGN_CONST	(NETDEV_ALIGN - 1)
 
 static inline
 struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
@@ -976,9 +975,7 @@ static inline bool netdev_uses_trailer_tags(struct net_device *dev)
  */
 static inline void *netdev_priv(const struct net_device *dev)
 {
-	return (char *)dev + ((sizeof(struct net_device)
-			       + NETDEV_ALIGN_CONST)
-			      & ~NETDEV_ALIGN_CONST);
+	return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
 }
 
 /* Set the sysfs physical device reference for the network logical device
diff --git a/net/core/dev.c b/net/core/dev.c
index ed4550f..32ceee1 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4988,18 +4988,18 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 	struct netdev_queue *tx;
 	struct net_device *dev;
 	size_t alloc_size;
-	void *p;
+	struct net_device *p;
 
 	BUG_ON(strlen(name) >= sizeof(dev->name));
 
 	alloc_size = sizeof(struct net_device);
 	if (sizeof_priv) {
 		/* ensure 32-byte alignment of private area */
-		alloc_size = (alloc_size + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
+		alloc_size = ALIGN(alloc_size, NETDEV_ALIGN);
 		alloc_size += sizeof_priv;
 	}
 	/* ensure 32-byte alignment of whole construct */
-	alloc_size += NETDEV_ALIGN_CONST;
+	alloc_size += NETDEV_ALIGN - 1;
 
 	p = kzalloc(alloc_size, ...
From: David Miller
Date: Wednesday, May 27, 2009 - 3:49 pm

From: Eric Dumazet <eric.dumazet@gmail.com>

Applied to net-next-2.6.
--

Previous thread: netfilter 02/04: nf_ct_dccp: add missing DCCP protocol changes in event cache by Patrick McHardy on Wednesday, May 27, 2009 - 7:35 am. (6 messages)

Next thread: (no subject) by ul on Wednesday, May 27, 2009 - 7:53 am. (1 message)