1 Index: linux-5.15.31/net/ethernet/eth.c
2 ===================================================================
3 --- linux-5.15.31.orig/net/ethernet/eth.c
4 +++ linux-5.15.31/net/ethernet/eth.c
5 @@ -544,6 +544,63 @@ int eth_platform_get_mac_address(struct
7 EXPORT_SYMBOL(eth_platform_get_mac_address);
9 +static void *nvmem_cell_get_mac_address(struct nvmem_cell *cell)
14 + mac = nvmem_cell_read(cell, &len);
16 + return PTR_ERR(mac);
17 + if (len != ETH_ALEN) {
19 + return ERR_PTR(-EINVAL);
24 +static void *nvmem_cell_get_mac_address_ascii(struct nvmem_cell *cell)
31 + mac_ascii = nvmem_cell_read(cell, &len);
32 + if (IS_ERR(mac_ascii))
33 + return PTR_ERR(mac_ascii);
34 + if (len != ETH_ALEN*2+5) {
36 + return ERR_PTR(-EINVAL);
38 + mac = kmalloc(ETH_ALEN, GFP_KERNEL);
41 + return ERR_PTR(-ENOMEM);
43 + ret = sscanf(mac_ascii, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
44 + &mac[0], &mac[1], &mac[2],
45 + &mac[3], &mac[4], &mac[5]);
47 + if (ret == ETH_ALEN)
50 + return ERR_PTR(-EINVAL);
53 +static struct nvmem_cell_mac_address_property {
55 + void *(*read)(struct nvmem_cell *);
56 +} nvmem_cell_mac_address_properties[] = {
58 + .name = "mac-address",
59 + .read = nvmem_cell_get_mac_address,
61 + .name = "mac-address-ascii",
62 + .read = nvmem_cell_get_mac_address_ascii,
67 * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
68 * 'mac-address' associated with given device.
69 @@ -557,19 +614,23 @@ int nvmem_get_mac_address(struct device
71 struct nvmem_cell *cell;
74 + struct nvmem_cell_mac_address_property *property;
77 - cell = nvmem_cell_get(dev, "mac-address");
79 - return PTR_ERR(cell);
81 - mac = nvmem_cell_read(cell, &len);
82 - nvmem_cell_put(cell);
85 - return PTR_ERR(mac);
86 + for (i = 0; i < ARRAY_SIZE(nvmem_cell_mac_address_properties); i++) {
87 + property = &nvmem_cell_mac_address_properties[i];
88 + cell = nvmem_cell_get(dev, property->name);
90 + if (i == ARRAY_SIZE(nvmem_cell_mac_address_properties) - 1)
91 + return PTR_ERR(cell);
94 + mac = property->read(cell);
95 + nvmem_cell_put(cell);
99 - if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
100 + if (!is_valid_ether_addr(mac)) {