ath25: switch default kernel to 5.15
[openwrt/staging/ldir.git] / target / linux / generic / pending-5.10 / 683-of_net-add-mac-address-to-of-tree.patch
1 From: David Bauer <mail@david-bauer.net>
2 Subject: of/net: Add MAC address to of tree
3
4 The label-mac logic relies on the mac-address property of a netdev
5 devices of-node. However, the mac address can also be stored as a
6 different property or read from e.g. an mtd device.
7
8 Create this node when reading a mac-address from OF if it does not
9 already exist and copy the mac-address used for the device to this
10 property. This way, the MAC address can be accessed using procfs.
11
12 Submitted-by: David Bauer <mail@david-bauer.net>
13 ---
14 drivers/of/of_net.c | 22 ++++++++++++++
15 1 files changed, 22 insertions(+)
16
17 --- a/drivers/of/of_net.c
18 +++ b/drivers/of/of_net.c
19 @@ -95,6 +95,27 @@ static int of_get_mac_addr_nvmem(struct
20 return 0;
21 }
22
23 +static int of_add_mac_address(struct device_node *np, u8* addr)
24 +{
25 + struct property *prop;
26 +
27 + prop = kzalloc(sizeof(*prop), GFP_KERNEL);
28 + if (!prop)
29 + return -ENOMEM;
30 +
31 + prop->name = "mac-address";
32 + prop->length = ETH_ALEN;
33 + prop->value = kmemdup(addr, ETH_ALEN, GFP_KERNEL);
34 + if (!prop->value || of_update_property(np, prop))
35 + goto free;
36 +
37 + return 0;
38 +free:
39 + kfree(prop->value);
40 + kfree(prop);
41 + return -ENOMEM;
42 +}
43 +
44 /**
45 * Search the device tree for the best MAC address to use. 'mac-address' is
46 * checked first, because that is supposed to contain to "most recent" MAC
47 @@ -171,6 +192,7 @@ found:
48 addr[5] = (mac_val >> 0) & 0xff;
49 }
50
51 + of_add_mac_address(np, addr);
52 return ret;
53 }
54 EXPORT_SYMBOL(of_get_mac_address);