Commit 1ce8e7b5 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: ALIGN/PTR_ALIGN cleanup in alloc_netdev_mq()/netdev_priv()

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

Get rid of NETDEV_ALIGN_CONST ugly define
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0bb32417
...@@ -905,7 +905,6 @@ struct net_device ...@@ -905,7 +905,6 @@ struct net_device
#define to_net_dev(d) container_of(d, struct net_device, dev) #define to_net_dev(d) container_of(d, struct net_device, dev)
#define NETDEV_ALIGN 32 #define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)
static inline static inline
struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, 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) ...@@ -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) static inline void *netdev_priv(const struct net_device *dev)
{ {
return (char *)dev + ((sizeof(struct net_device) return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
+ NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
} }
/* Set the sysfs physical device reference for the network logical device /* Set the sysfs physical device reference for the network logical device
......
...@@ -4988,18 +4988,18 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, ...@@ -4988,18 +4988,18 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
struct netdev_queue *tx; struct netdev_queue *tx;
struct net_device *dev; struct net_device *dev;
size_t alloc_size; size_t alloc_size;
void *p; struct net_device *p;
BUG_ON(strlen(name) >= sizeof(dev->name)); BUG_ON(strlen(name) >= sizeof(dev->name));
alloc_size = sizeof(struct net_device); alloc_size = sizeof(struct net_device);
if (sizeof_priv) { if (sizeof_priv) {
/* ensure 32-byte alignment of private area */ /* 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; alloc_size += sizeof_priv;
} }
/* ensure 32-byte alignment of whole construct */ /* ensure 32-byte alignment of whole construct */
alloc_size += NETDEV_ALIGN_CONST; alloc_size += NETDEV_ALIGN - 1;
p = kzalloc(alloc_size, GFP_KERNEL); p = kzalloc(alloc_size, GFP_KERNEL);
if (!p) { if (!p) {
...@@ -5014,8 +5014,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, ...@@ -5014,8 +5014,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
goto free_p; goto free_p;
} }
dev = (struct net_device *) dev = PTR_ALIGN(p, NETDEV_ALIGN);
(((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
dev->padded = (char *)dev - (char *)p; dev->padded = (char *)dev - (char *)p;
if (dev_addr_init(dev)) if (dev_addr_init(dev))
......
...@@ -735,9 +735,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, ...@@ -735,9 +735,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
* +-------------------------+ * +-------------------------+
* *
*/ */
priv_size = ((sizeof(struct ieee80211_local) + priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
priv_data_len;
wiphy = wiphy_new(&mac80211_config_ops, priv_size); wiphy = wiphy_new(&mac80211_config_ops, priv_size);
...@@ -754,9 +752,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, ...@@ -754,9 +752,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
local->hw.wiphy = wiphy; local->hw.wiphy = wiphy;
local->hw.priv = (char *)local + local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
((sizeof(struct ieee80211_local) +
NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
BUG_ON(!ops->tx); BUG_ON(!ops->tx);
BUG_ON(!ops->start); BUG_ON(!ops->start);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment