lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 11 May 2020 17:07:50 +0200
From:   Bartosz Golaszewski <>
To:     Rob Herring <>,
        "David S . Miller" <>,
        Matthias Brugger <>,
        John Crispin <>,
        Sean Wang <>,
        Mark Lee <>,
        Jakub Kicinski <>,
        Arnd Bergmann <>,
        Fabien Parent <>,
        Heiner Kallweit <>,
        Edwin Peer <>
        Stephane Le Provost <>,
        Pedro Tsai <>,
        Andrew Perepech <>,
        Bartosz Golaszewski <>
Subject: [PATCH v2 05/14] net: core: provide priv_to_netdev()

From: Bartosz Golaszewski <>

Appropriate amount of extra memory for private data is allocated at
the end of struct net_device. We have a helper - netdev_priv() - that
returns its address but we don't have the reverse: a function which
given the address of the private data, returns the address of struct

This has caused many drivers to store the pointer to net_device in
the private data structure, which basically means storing the pointer
to a structure in this very structure.

This patch proposes to add priv_to_netdev() - a helper which converts
the address of the private data to the address of the associated

Signed-off-by: Bartosz Golaszewski <>
 include/linux/netdevice.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 130a668049ab..933c6808a87f 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2249,6 +2249,18 @@ static inline void *netdev_priv(const struct net_device *dev)
 	return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
+ *	priv_to_netdev - get the net_device from private data
+ *	@priv: net_device private data
+ *
+ * Get the address of network device associated with this private data.
+ */
+static inline struct net_device *priv_to_netdev(void *priv)
+	priv = (char *)priv - ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
+	return (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.

Powered by blists - more mailing lists