Skip to contentSkip to conversation

net: add netdev_from_priv() helper

PATCH Superseded Qingfang Deng 3 participants 3 messages Mar 19

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: add netdev_from_priv() helper

Add a helper to get netdev from private data pointer, so drivers won't have to store redundant netdev in priv.

---
 include/linux/netdevice.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/netdevice.h +11 -0
index ae269a2e7f4d..dba96736202a 100644
@@ -2764,6 +2764,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
+ *
+ * Get network device from private data pointer
+ */
+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.
  */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 2 lines · Qingfang Deng

Add a helper to get netdev from private data pointer, so drivers won't have to store redundant netdev in priv.

You always need to include a user when adding a new API.

Andrew

---
pw-bot: cr

maintainer
#2 lore raw
In reply to Qingfang Deng

include/linux/netdevice.h static inline void *netdev_priv(const struct net_device *dev) · line 2775

Quoted 9 lines · On Thu, 19 Mar 2026 10:26:08 +0800 Qingfang Deng wrote:
include/linux/netdevice.h +9 -0
+/**
+ *	netdev_from_priv - get network device from priv
+ *	@priv: network device private data
+ *
+ * Get network device from private data pointer
+ */
+static inline struct net_device *netdev_from_priv(const void *priv)
+{
+	return container_of(priv, struct net_device, priv);

When you repost this with a user please format the kdoc as:

+/**
+ * netdev_from_priv() - get network device from priv
+ * @priv: network device private data
+ *
+ * Returns: net_device to which @priv belongs
+ */