Skip to content

Commit

Permalink
of: of_net: use a loop
Browse files Browse the repository at this point in the history
iterate over the different property names rather than having
the same code three times.

Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
saschahauer committed Apr 12, 2017
1 parent f2cca54 commit bd3b279
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions drivers/of/of_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit bd3b279

Please sign in to comment.