[PATCH 3/4] net: register eth class

Sascha Hauer s.hauer at pengutronix.de
Mon Jun 10 01:12:12 PDT 2024


Register network devices as class devices. This allows us to implement
for_each_netdev() by iterating over the network class devices.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/net.h | 4 ++--
 net/eth.c     | 6 ++++--
 net/ifup.c    | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/net.h b/include/net.h
index 5a6dd9ca7b..edfea0d105 100644
--- a/include/net.h
+++ b/include/net.h
@@ -599,8 +599,8 @@ void ifdown_edev(struct eth_device *edev);
 int ifdown(const char *name);
 void ifdown_all(void);
 
-extern struct list_head netdev_list;
+#define for_each_netdev(netdev) list_for_each_entry(netdev, &eth_class.devices, dev.class_list)
 
-#define for_each_netdev(netdev) list_for_each_entry(netdev, &netdev_list, list)
+extern struct class eth_class;
 
 #endif /* __NET_H__ */
diff --git a/net/eth.c b/net/eth.c
index 26a36474f8..74386d6e7b 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -21,7 +21,7 @@
 #include <linux/ctype.h>
 #include <linux/stat.h>
 
-LIST_HEAD(netdev_list);
+DECLARE_CLASS(eth_class, "eth");
 
 struct eth_ethaddr {
 	struct list_head list;
@@ -445,7 +445,7 @@ int eth_register(struct eth_device *edev)
 	if (edev->init)
 		edev->init(edev);
 
-	list_add_tail(&edev->list, &netdev_list);
+	class_add_device(&eth_class, &edev->dev);
 
 	ret = eth_get_registered_ethaddr(edev, ethaddr);
 	if (!ret)
@@ -512,6 +512,8 @@ void eth_unregister(struct eth_device *edev)
 	if (IS_ENABLED(CONFIG_OFDEVICE))
 		free(edev->nodepath);
 
+	class_remove_device(&eth_class, &edev->dev);
+
 	free(edev->devname);
 
 	unregister_device(&edev->dev);
diff --git a/net/ifup.c b/net/ifup.c
index 5b92ee794d..41c1942670 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -358,7 +358,7 @@ int ifup_all(unsigned flags)
 	closedir(dir);
 
 	if ((flags & IFUP_FLAG_FORCE) || net_ifup_force_detect ||
-	    list_empty(&netdev_list))
+	    list_empty(&eth_class.devices))
 		device_detect_all();
 
 	/*
-- 
2.39.2




More information about the barebox mailing list