diff mbox series

backports: add alloc_netdev_dummy and free_netdev

Message ID 20240611111059.23455-2-johannes@sipsolutions.net (mailing list archive)
State New, archived
Headers show
Series backports: add alloc_netdev_dummy and free_netdev | expand

Commit Message

Johannes Berg June 11, 2024, 11:11 a.m. UTC
From: Miri Korenblit <miriam.rachel.korenblit@intel.com>

Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 backport/backport-include/linux/netdevice.h | 29 +++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h
index 7f72c3a8eb98..58b8d0c68ed2 100644
--- a/backport/backport-include/linux/netdevice.h
+++ b/backport/backport-include/linux/netdevice.h
@@ -212,4 +212,33 @@  static inline bool napi_is_scheduled(struct napi_struct *n)
 }
 #endif /* < 6.7.0 */
 
+#if LINUX_VERSION_IS_LESS(6,10,0)
+static inline struct net_device *alloc_netdev_dummy(int sizeof_priv)
+{
+	struct net_device *dev;
+
+	dev = kzalloc(sizeof(*dev) +
+		      ALIGN(sizeof(struct net_device), NETDEV_ALIGN) +
+		      sizeof_priv,
+		      GFP_KERNEL);
+
+	if (!dev)
+		return NULL;
+
+	init_dummy_netdev(dev);
+	return dev;
+}
+
+static inline void LINUX_BACKPORT(free_netdev)(struct net_device *dev)
+{
+	if (dev->reg_state == NETREG_DUMMY) {
+		kfree(dev);
+		return;
+	}
+
+	free_netdev(dev);
+}
+#define free_netdev LINUX_BACKPORT(free_netdev)
+#endif /* 6.10.0 */
+
 #endif /* __BACKPORT_NETDEVICE_H */