netdev->priv and netdev_priv(dev)
Subsystems (2)
A commit few months ago introduced a change:
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
static inline void *netdev_priv(const struct net_device *dev) {
- return (char *)dev + ((sizeof(struct net_device)
- + NETDEV_ALIGN_CONST)
- & ~NETDEV_ALIGN_CONST);
+ return dev->priv;
}
This change caused some problems for drivers which used netdev_priv(dev) and dev->priv for different purposes.
The following patch restores previous behaviour.
include/linux/netdevice.h +4 -1
@@ -584,7 +584,10 @@ struct net_devicestatic inline void *netdev_priv (const struct net_device *dev) { -return dev->priv; +return (char *)dev + ((sizeof (struct net_device ) + +sizeof (struct net_device_subqueue ) * + (dev->egress_subqueue_count -1 ) + +NETDEV_ALIGN_CONST ) & ~NETDEV_ALIGN_CONST ); }#define SET_MODULE_OWNER (dev) do { } while (0)
net/core/dev.c +2 -7
@@ -3693,13 +3693,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, (((long )p +NETDEV_ALIGN_CONST ) & ~NETDEV_ALIGN_CONST ); dev->padded = (char *)dev - (char *)p; -if (sizeof_priv) { - dev->priv = ((char *)dev + - ((sizeof (struct net_device ) + - (sizeof (struct net_device_subqueue ) * - (queue_count -1 )) +NETDEV_ALIGN_CONST ) - & ~NETDEV_ALIGN_CONST )); - } +if (sizeof_priv) + dev->priv =netdev_priv (dev); dev->egress_subqueue_count = queue_count;
Quoted 13 lines · On Tue, 29 Jan 2008 21:10:00 +0100 Krzysztof Halasa <[email protected]> wrote:
A commit few months ago introduced a change:
include/linux/netdevice.h +1
-3static inline void *netdev_priv (const struct net_device *dev) { -return (char *)dev + ((sizeof (struct net_device ) - +NETDEV_ALIGN_CONST ) - & ~NETDEV_ALIGN_CONST ); +return dev->priv; }
Quoted 3 lines
This change caused some problems for drivers which used
netdev_priv(dev)anddev->privfor different purposes.
Those drivers were making a incorrect assumption and should be fixed. The in-tree drivers were fixed when this was done. If you have an out of tree driver, then too bad for you.
Quoted 27 lines
The following patch restores previous behaviour.
Signed-off-by Krzysztof Halasa <[email protected]>include/linux/netdevice.h +4
-1@@ -584,7 +584,10 @@ struct net_devicestatic inline void *netdev_priv (const struct net_device *dev) { -return dev->priv; +return (char *)dev + ((sizeof (struct net_device ) + +sizeof (struct net_device_subqueue ) * + (dev->egress_subqueue_count -1 ) + +NETDEV_ALIGN_CONST ) & ~NETDEV_ALIGN_CONST ); }#define SET_MODULE_OWNER (dev) do { } while (0)net/core/dev.c +0
-2@@ -3693,13 +3693,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, (((long )p +NETDEV_ALIGN_CONST ) & ~NETDEV_ALIGN_CONST ); dev->padded = (char *)dev - (char *)p; -if (sizeof_priv) { - dev->priv = ((char *)dev +
net/core/dev.c struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, · line 3700
Quoted 10 lines
net/core/dev.c +2
-5- ((sizeof (struct net_device ) + - (sizeof (struct net_device_subqueue ) * - (queue_count -1 )) +NETDEV_ALIGN_CONST ) - & ~NETDEV_ALIGN_CONST)); - } +if (sizeof_priv) + dev->priv =netdev_priv (dev); dev->egress_subqueue_count = queue_count;
The additional overhead of the address calculation would slow down the well behaved drivers. There was discussion of alternative layouts of the network device allocation or limiting the number of subqueue's so that netdev_priv could be a simple addition again, but nothing came of it.
Signature · 1 line
Stephen Hemminger <[email protected]>
Quoted 3 lines · Stephen Hemminger
Those drivers were making a incorrect assumption and should be fixed. The in-tree drivers were fixed when this was done. If you have an out of tree driver, then too bad for you.
I have few out-of-tree drivers (IOW not yet merged) but they aren't affected. These in the tree are (actually I was contacted by driver's author and am considering the best way to fix this).
Quoted 2 lines
The additional overhead of the address calculation would slow down the well behaved drivers.
There is always dev->priv.
Quoted 4 lines
There was discussion of alternative layouts of
the network device allocation or limiting the number of subqueue's so thatnetdev_privcould be a simple addition again, but nothing came of it.
This isn't about an addition, netdev_priv() is still there. The semantics silently changed, that's it.
I'm fine with its removal, is it ok? The trivial "return dev->priv" isn't worth it anyway.
Signature · 1 line
Krzysztof Halasa