Commit 5b902d6f authored by Julien Grall's avatar Julien Grall Committed by David S. Miller

device property: Don't overwrite addr when failing in device_get_mac_address

The function device_get_mac_address is trying different property names
in order to get the mac address. To check the return value, the variable
addr (which contain the buffer pass by the caller) will be re-used. This
means that if the previous property is not found, the next property will
be read using a NULL buffer.

Therefore it's only possible to retrieve the mac if node contains a
property "mac-address". Fix it by using a temporary buffer for the
return value.

This has been introduced by commit 4c96b7dc
"Add a matching set of device_ functions for determining mac/phy"
Signed-off-by: default avatarJulien Grall <julien.grall@citrix.com>
Cc: Jeremy Linton <jeremy.linton@arm.com>
Cc: David S. Miller <davem@davemloft.net>
Reviewed-by: default avatarJeremy Linton <jeremy.linton@arm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fcb0bb6a
...@@ -611,13 +611,15 @@ static void *device_get_mac_addr(struct device *dev, ...@@ -611,13 +611,15 @@ static void *device_get_mac_addr(struct device *dev,
*/ */
void *device_get_mac_address(struct device *dev, char *addr, int alen) void *device_get_mac_address(struct device *dev, char *addr, int alen)
{ {
addr = device_get_mac_addr(dev, "mac-address", addr, alen); char *res;
if (addr)
return addr;
addr = device_get_mac_addr(dev, "local-mac-address", addr, alen); res = device_get_mac_addr(dev, "mac-address", addr, alen);
if (addr) if (res)
return addr; return res;
res = device_get_mac_addr(dev, "local-mac-address", addr, alen);
if (res)
return res;
return device_get_mac_addr(dev, "address", addr, alen); return device_get_mac_addr(dev, "address", addr, alen);
} }
......
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