lists.openwall.net   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  linux-cve-announce  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]
Message-ID: <1c618e2d-049c-7dfa-0f82-5f32fa4e9322@gmail.com>
Date:   Thu, 15 Oct 2020 17:49:20 +0200
From:   Heiner Kallweit <hkallweit1@...il.com>
To:     David Miller <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Realtek linux nic maintainers <nic_swsd@...ltek.com>
Cc:     "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: [PATCH net-next 2/4] net: core: add devm_netdev_alloc_pcpu_stats

Add a managed version of netdev_alloc_pcpu_stats, e.g. for allocating
the per-cpu stats in the probe() callback of a driver. It needs to be
a macro for dealing properly with the type argument.

Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
---
 include/linux/netdevice.h | 15 +++++++++++++++
 net/devres.c              |  6 ++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 568fab708..f5f41c160 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2596,6 +2596,21 @@ static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
 #define netdev_alloc_pcpu_stats(type)					\
 	__netdev_alloc_pcpu_stats(type, GFP_KERNEL)
 
+void devm_free_pcpu_stats(void *data);
+
+#define devm_netdev_alloc_pcpu_stats(dev, type)				\
+({									\
+	typeof(type) __percpu *pcpu_stats = netdev_alloc_pcpu_stats(type); \
+	if (pcpu_stats) {						\
+		int rc = devm_add_action_or_reset(dev,			\
+					devm_free_pcpu_stats,		\
+					(__force void *)pcpu_stats);	\
+		if (rc)							\
+			pcpu_stats = NULL;				\
+	}								\
+	pcpu_stats;							\
+})
+
 enum netdev_lag_tx_type {
 	NETDEV_LAG_TX_TYPE_UNKNOWN,
 	NETDEV_LAG_TX_TYPE_RANDOM,
diff --git a/net/devres.c b/net/devres.c
index 1f9be2133..0d6545946 100644
--- a/net/devres.c
+++ b/net/devres.c
@@ -93,3 +93,9 @@ int devm_register_netdev(struct device *dev, struct net_device *ndev)
 	return 0;
 }
 EXPORT_SYMBOL(devm_register_netdev);
+
+void devm_free_pcpu_stats(void *data)
+{
+	free_percpu((__force void __percpu *)data);
+}
+EXPORT_SYMBOL_GPL(devm_free_pcpu_stats);
-- 
2.28.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ