1 --- a/net/ethernet/eth.c
2 +++ b/net/ethernet/eth.c
3 @@ -544,6 +544,63 @@ int eth_platform_get_mac_address(struct
5 EXPORT_SYMBOL(eth_platform_get_mac_address);
7 +static void *nvmem_cell_get_mac_address(struct nvmem_cell *cell)
12 + mac = nvmem_cell_read(cell, &len);
14 + return PTR_ERR(mac);
15 + if (len != ETH_ALEN) {
17 + return ERR_PTR(-EINVAL);
22 +static void *nvmem_cell_get_mac_address_ascii(struct nvmem_cell *cell)
29 + mac_ascii = nvmem_cell_read(cell, &len);
30 + if (IS_ERR(mac_ascii))
31 + return PTR_ERR(mac_ascii);
32 + if (len != ETH_ALEN*2+5) {
34 + return ERR_PTR(-EINVAL);
36 + mac = kmalloc(ETH_ALEN, GFP_KERNEL);
39 + return ERR_PTR(-ENOMEM);
41 + ret = sscanf(mac_ascii, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
42 + &mac[0], &mac[1], &mac[2],
43 + &mac[3], &mac[4], &mac[5]);
45 + if (ret == ETH_ALEN)
48 + return ERR_PTR(-EINVAL);
51 +static struct nvmem_cell_mac_address_property {
53 + void *(*read)(struct nvmem_cell *);
54 +} nvmem_cell_mac_address_properties[] = {
56 + .name = "mac-address",
57 + .read = nvmem_cell_get_mac_address,
59 + .name = "mac-address-ascii",
60 + .read = nvmem_cell_get_mac_address_ascii,
65 * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
66 * 'mac-address' associated with given device.
67 @@ -557,19 +614,23 @@ int nvmem_get_mac_address(struct device
69 struct nvmem_cell *cell;
72 + struct nvmem_cell_mac_address_property *property;
75 - cell = nvmem_cell_get(dev, "mac-address");
77 - return PTR_ERR(cell);
79 - mac = nvmem_cell_read(cell, &len);
80 - nvmem_cell_put(cell);
83 - return PTR_ERR(mac);
84 + for (i = 0; i < ARRAY_SIZE(nvmem_cell_mac_address_properties); i++) {
85 + property = &nvmem_cell_mac_address_properties[i];
86 + cell = nvmem_cell_get(dev, property->name);
88 + if (i == ARRAY_SIZE(nvmem_cell_mac_address_properties) - 1)
89 + return PTR_ERR(cell);
92 + mac = property->read(cell);
93 + nvmem_cell_put(cell);
97 - if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
98 + if (!is_valid_ether_addr(mac)) {