[PATCH 2/2] of: of_net: use a loop
Sascha Hauer
s.hauer at pengutronix.de
Wed Apr 12 03:13:36 PDT 2017
iterate over the different property names rather than having
the same code three times.
Signed-off-by: Sascha Hauer <s.hauer at 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
More information about the barebox
mailing list