kernel: fix mac-address-increment patch
[openwrt/openwrt.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 @@ -95,6 +95,27 @@ static int of_get_mac_addr_nvmem(struct
4 return 0;
5 }
6
7 +static int of_add_mac_address(struct device_node *np, u8* addr)
8 +{
9 + struct property *prop;
10 +
11 + prop = kzalloc(sizeof(*prop), GFP_KERNEL);
12 + if (!prop)
13 + return -ENOMEM;
14 +
15 + prop->name = "mac-address";
16 + prop->length = ETH_ALEN;
17 + prop->value = kmemdup(addr, ETH_ALEN, GFP_KERNEL);
18 + if (!prop->value || of_update_property(np, prop))
19 + goto free;
20 +
21 + return 0;
22 +free:
23 + kfree(prop->value);
24 + kfree(prop);
25 + return -ENOMEM;
26 +}
27 +
28 /**
29 * Search the device tree for the best MAC address to use. 'mac-address' is
30 * checked first, because that is supposed to contain to "most recent" MAC
31 @@ -171,6 +192,7 @@ found:
32 addr[5] = (mac_val >> 0) & 0xff;
33 }
34
35 + of_add_mac_address(np, addr);
36 return ret;
37 }
38 EXPORT_SYMBOL(of_get_mac_address);