Commit 9ed319e4 authored by Rafał Miłecki's avatar Rafał Miłecki Committed by David S. Miller

of: net: support NVMEM cells with MAC in text format

Some NVMEM devices have text based cells. In such cases MAC is stored in
a XX:XX:XX:XX:XX:XX format. Use mac_pton() to parse such data and
support those NVMEM cells. This is required to support e.g. a very
popular U-Boot and its environment variables.
Signed-off-by: default avatarRafał Miłecki <rafal@milecki.pl>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 271d3be1
...@@ -61,7 +61,7 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr) ...@@ -61,7 +61,7 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
{ {
struct platform_device *pdev = of_find_device_by_node(np); struct platform_device *pdev = of_find_device_by_node(np);
struct nvmem_cell *cell; struct nvmem_cell *cell;
const void *mac; const void *buf;
size_t len; size_t len;
int ret; int ret;
...@@ -78,21 +78,32 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr) ...@@ -78,21 +78,32 @@ static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
if (IS_ERR(cell)) if (IS_ERR(cell))
return PTR_ERR(cell); return PTR_ERR(cell);
mac = nvmem_cell_read(cell, &len); buf = nvmem_cell_read(cell, &len);
nvmem_cell_put(cell); nvmem_cell_put(cell);
if (IS_ERR(mac)) if (IS_ERR(buf))
return PTR_ERR(mac); return PTR_ERR(buf);
if (len != ETH_ALEN || !is_valid_ether_addr(mac)) { ret = 0;
kfree(mac); if (len == ETH_ALEN) {
return -EINVAL; if (is_valid_ether_addr(buf))
} memcpy(addr, buf, ETH_ALEN);
else
ret = -EINVAL;
} else if (len == 3 * ETH_ALEN - 1) {
u8 mac[ETH_ALEN];
if (mac_pton(buf, mac))
memcpy(addr, mac, ETH_ALEN); memcpy(addr, mac, ETH_ALEN);
kfree(mac); else
ret = -EINVAL;
} else {
ret = -EINVAL;
}
return 0; kfree(buf);
return ret;
} }
/** /**
......
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