]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: add netdev_from_priv() helper
authorQingfang Deng <dqfext@gmail.com>
Fri, 20 Mar 2026 07:56:03 +0000 (15:56 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 24 Mar 2026 00:51:59 +0000 (17:51 -0700)
Add a helper to get netdev from private data pointer, so drivers won't
have to store redundant netdev in priv.

Signed-off-by: Qingfang Deng <dqfext@gmail.com>
Link: https://patch.msgid.link/20260320075605.490832-1-dqfext@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/netdevice.h

index 7ca01eb3f7d2b22a188502583dc95121adff7cc9..6882b41bb3e82edd128846e31e9e805fe0492518 100644 (file)
@@ -2765,6 +2765,17 @@ static inline void *netdev_priv(const struct net_device *dev)
        return (void *)dev->priv;
 }
 
+/**
+ * netdev_from_priv() - get network device from priv
+ * @priv: network device private data
+ *
+ * Returns: net_device to which @priv belongs
+ */
+static inline struct net_device *netdev_from_priv(const void *priv)
+{
+       return container_of(priv, struct net_device, priv);
+}
+
 /* Set the sysfs physical device reference for the network logical device
  * if set prior to registration will cause a symlink during initialization.
  */