mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/5] net: introduce for_each_netdev iterator
Date: Fri, 15 Jul 2016 09:23:07 +0200	[thread overview]
Message-ID: <1468567389-28169-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1468567389-28169-1-git-send-email-s.hauer@pengutronix.de>

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 <s.hauer@pengutronix.de>
---
 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 13e335a..81118d2 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 6bec154..499f4b0 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;
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-07-15  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-15  7:23 [PATCH 1/5] net: usb: use minimum timeout when polling for new packets Sascha Hauer
2016-07-15  7:23 ` [PATCH 2/5] net: eth: open correct edev in eth_check_open Sascha Hauer
2016-07-15  7:23 ` Sascha Hauer [this message]
2016-07-15  7:23 ` [PATCH 4/5] net: eth: add name to struct eth_device Sascha Hauer
2016-07-15  7:23 ` [PATCH 5/5] net: Pass network device to net_answer_arp() Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468567389-28169-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox