Commit 3eb46a1d authored by Sergei Shtylyov's avatar Sergei Shtylyov Committed by Grant Likely

of_net: factor out repetitive code from of_get_mac_address()

of_get_mac_address() basically does the same  thing thrice, every  time with  a
different  property  name,  so it makes sense to factor out the repetitive code
into separate function. While at it, we can start using ETH_ALEN instead of the
bare number and drop unnecessary parens around the property length check.

The resulting ARM object file is 100 bytes less in size than before the patch.
Signed-off-by: default avatarSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarGrant Likely <grant.likely@linaro.org>
parent a5ed1ad0
...@@ -38,6 +38,15 @@ int of_get_phy_mode(struct device_node *np) ...@@ -38,6 +38,15 @@ int of_get_phy_mode(struct device_node *np)
} }
EXPORT_SYMBOL_GPL(of_get_phy_mode); EXPORT_SYMBOL_GPL(of_get_phy_mode);
static const void *of_get_mac_addr(struct device_node *np, const char *name)
{
struct property *pp = of_find_property(np, name, NULL);
if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value))
return pp->value;
return NULL;
}
/** /**
* Search the device tree for the best MAC address to use. 'mac-address' is * Search the device tree for the best MAC address to use. 'mac-address' is
* checked first, because that is supposed to contain to "most recent" MAC * checked first, because that is supposed to contain to "most recent" MAC
...@@ -58,20 +67,16 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode); ...@@ -58,20 +67,16 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode);
*/ */
const void *of_get_mac_address(struct device_node *np) const void *of_get_mac_address(struct device_node *np)
{ {
struct property *pp; const void *addr;
pp = of_find_property(np, "mac-address", NULL); addr = of_get_mac_addr(np, "mac-address");
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) if (addr)
return pp->value; return addr;
pp = of_find_property(np, "local-mac-address", NULL); addr = of_get_mac_addr(np, "local-mac-address");
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value)) if (addr)
return pp->value; return addr;
pp = of_find_property(np, "address", NULL); return of_get_mac_addr(np, "address");
if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
return pp->value;
return NULL;
} }
EXPORT_SYMBOL(of_get_mac_address); EXPORT_SYMBOL(of_get_mac_address);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment