diff options
authorJason A. Donenfeld <Jason@zx2c4.com>2015-06-12 15:26:42 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-07-10 05:09:26 +0200
commit2335ad0c7a509d9f488238906bb320d65b647871 (patch)
parentafs: Add metadata xattrs (diff)
netdevice: add netdev_pub helper function
Being able to utilize this makes code a lot simpler and cleaner. It's easier in many cases for drivers to pass around their private data structure, while occationally needing to dip into net_device, rather than the other way around, which results in tons of calls to netdev_priv in the top of every single function, which makes everything confusing and less clear. Additionally, this enables a "correct" way of doing such a thing, instead of having drivers attempt to reinvent the wheel and screw it up. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 779b23595596..83d58504e5c4 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2040,6 +2040,17 @@ static inline void *netdev_priv(const struct net_device *dev)
return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
+ * netdev_pub - access network device from private pointer
+ * @priv: private data pointer of network device
+ *
+ * Get network device from a network device private data pointer
+ */
+static inline struct net_device *netdev_pub(void *priv)
+ return (struct net_device *)((char *)priv - ALIGN(sizeof(struct net_device), NETDEV_ALIGN));
/* Set the sysfs physical device reference for the network logical device
* if set prior to registration will cause a symlink during initialization.