From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/2] of: of_net: use a loop
Date: Wed, 12 Apr 2017 12:13:36 +0200 [thread overview]
Message-ID: <20170412101336.32256-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170412101336.32256-1-s.hauer@pengutronix.de>
iterate over the different property names rather than having
the same code three times.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/of_net.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 086573fc1a..9b54e44674 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -77,19 +77,15 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode);
*/
const void *of_get_mac_address(struct device_node *np)
{
- struct property *pp;
+ const void *p;
+ int len, i;
+ const char *str[] = { "mac-address", "local-mac-address", "address" };
- pp = of_find_property(np, "mac-address", NULL);
- if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
- return pp->value;
-
- pp = of_find_property(np, "local-mac-address", NULL);
- if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
- return pp->value;
-
- pp = of_find_property(np, "address", NULL);
- if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
- return pp->value;
+ for (i = 0; i < ARRAY_SIZE(str); i++) {
+ p = of_get_property(np, str[i], &len);
+ if (p && (len == 6) && is_valid_ether_addr(p))
+ return p;
+ }
return NULL;
}
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2017-04-12 10:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 10:13 [PATCH 1/2] of: use of_property_read_bool where appropriate Sascha Hauer
2017-04-12 10:13 ` Sascha Hauer [this message]
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=20170412101336.32256-2-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