From 8b3244d3a8e06d743c58324ab407e3746c4e1e84 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 3 Feb 2011 13:14:38 +0100 Subject: net: introduce for_each_netdev iterator for_each_netdev is nicer to read. Also export the list of network devices since it will be used by code outside of net/eth.c in later patches. Signed-off-by: Sascha Hauer --- include/net.h | 4 ++++ net/eth.c | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/net.h b/include/net.h index 13e335aac2..81118d26dc 100644 --- a/include/net.h +++ b/include/net.h @@ -466,4 +466,8 @@ void led_trigger_network(enum led_trigger trigger); int ifup(const char *name, unsigned flags); int ifup_all(unsigned flags); +extern struct list_head netdev_list; + +#define for_each_netdev(netdev) list_for_each_entry(netdev, &netdev_list, list) + #endif /* __NET_H__ */ diff --git a/net/eth.c b/net/eth.c index 6bec154f36..499f4b04da 100644 --- a/net/eth.c +++ b/net/eth.c @@ -31,7 +31,7 @@ static struct eth_device *eth_current; static uint64_t last_link_check; -static LIST_HEAD(netdev_list); +LIST_HEAD(netdev_list); struct eth_ethaddr { struct list_head list; @@ -104,7 +104,7 @@ void eth_register_ethaddr(int ethid, const char *ethaddr) eth_drop_ethaddr(ethid); - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (edev->dev.id == ethid) { register_preset_mac_address(edev, ethaddr); return; @@ -121,7 +121,7 @@ static struct eth_device *eth_get_by_node(struct device_node *node) { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (!edev->parent) continue; if (!edev->parent->device_node) @@ -163,7 +163,7 @@ struct eth_device *eth_get_byname(const char *ethname) { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (!strcmp(ethname, dev_name(&edev->dev))) return edev; } @@ -179,7 +179,7 @@ int eth_complete(struct string_list *sl, char *instr) len = strlen(instr); - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { devname = dev_name(&edev->dev); if (strncmp(instr, devname, len)) continue; @@ -273,7 +273,7 @@ int eth_rx(void) { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { + for_each_netdev(edev) { if (edev->active) __eth_rx(edev); } @@ -337,7 +337,7 @@ static int eth_of_fixup(struct device_node *root, void *unused) eth_of_fixup_node(root, addr->node ? addr->node->full_name : NULL, addr->ethid, addr->ethaddr); - list_for_each_entry(edev, &netdev_list, list) + for_each_netdev(edev) eth_of_fixup_node(root, edev->nodepath, edev->dev.id, edev->ethaddr); return 0; -- cgit v1.2.3