generic: fix build warning
[openwrt/staging/ldir.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,33 @@ static void *of_get_mac_address_mtd(stru
4 return NULL;
5 }
6
7 +static int of_add_mac_address(struct device_node *np, u8* addr)
8 +{
9 + struct property *prop;
10 + u8 *np_addr;
11 +
12 + np_addr = of_get_mac_addr(np, "mac-address");
13 + if (np_addr) {
14 + memcpy(np_addr, addr, ETH_ALEN);
15 + return 0;
16 + }
17 +
18 + prop = kzalloc(sizeof(*prop), GFP_KERNEL);
19 + if (!prop)
20 + return 0;
21 +
22 + prop->name = "mac-address";
23 + prop->length = ETH_ALEN;
24 + prop->value = kmemdup(addr, ETH_ALEN, GFP_KERNEL);
25 + if (!prop->value || of_add_property(np, prop))
26 + goto free;
27 +
28 + return 0;
29 +free:
30 + kfree(prop->value);
31 + kfree(prop);
32 + return -ENOMEM;
33 +}
34
35 /**
36 * Search the device tree for the best MAC address to use. 'mac-address' is
37 @@ -205,6 +232,7 @@ found:
38 if (!of_property_read_u32(np, "mac-address-increment", &mac_inc))
39 addr[inc_idx] += mac_inc;
40
41 + of_add_mac_address(np, addr);
42 return addr;
43 }
44 EXPORT_SYMBOL(of_get_mac_address);