treewide: backport support for nvmem on non platform devices
[openwrt/staging/wigyori.git] / target / linux / generic / pending-5.10 / 683-of_net-add-mac-address-to-of-tree.patch
1 --- a/drivers/of/of_net.c
2 +++ b/drivers/of/of_net.c
3 @@ -132,6 +132,30 @@ static void *of_get_mac_address_mtd(stru
4 return -EINVAL;
5 }
6
7 +static int of_add_mac_address(struct device_node *np, u8* addr)
8 +{
9 + struct property *prop;
10 +
11 + prop = of_find_property(np, "mac-address", NULL);
12 + if (prop)
13 + kfree(prop);
14 +
15 + prop = kzalloc(sizeof(*prop), GFP_KERNEL);
16 + if (!prop)
17 + return 0;
18 +
19 + prop->name = "mac-address";
20 + prop->length = ETH_ALEN;
21 + prop->value = kmemdup(addr, ETH_ALEN, GFP_KERNEL);
22 + if (!prop->value || of_add_property(np, prop))
23 + goto free;
24 +
25 + return 0;
26 +free:
27 + kfree(prop->value);
28 + kfree(prop);
29 + return -ENOMEM;
30 +}
31
32 /**
33 * Search the device tree for the best MAC address to use. 'mac-address' is
34 @@ -205,6 +232,7 @@ found:
35 if (!of_property_read_u32(np, "mac-address-increment", &mac_inc))
36 addr[inc_idx] += mac_inc;
37
38 + of_add_mac_address(np, addr);
39 return ret;
40 }
41 EXPORT_SYMBOL(of_get_mac_address);