de561c5336c3f7678ee33fad00dc36a57ad62faf
[openwrt/openwrt.git] / target / linux / generic / hack-5.4 / 683-NET-add-mac-address-property.patch
1 From: David Bauer <mail@david-bauer.net>
2 Date: Tue, 20 Jul 2021 22:00:10 +0200
3 Subject: [PATCH] generic: add mac-address property for NVMEM mac addresses
4
5 Traversing the device-tree by referencing a network device to determine
6 a devices labe-mac does not work with the generic nvmem implementation,
7 as the userspace expects the MAC-address to be available as a
8 device-tree property.
9
10 The legacy mtd-mac-address implementation did create such a node. Do the
11 same when using the nvmem implementation to allow reading the MAC
12 address.
13
14 Fixes commit d284e6ef0f06 ("treewide: convert mtd-mac-address-increment*
15 to generic implementation")
16
17 Signed-off-by: David Bauer <mail@david-bauer.net>
18
19 --- a/drivers/of/of_net.c
20 +++ b/drivers/of/of_net.c
21 @@ -61,6 +61,7 @@ static void *of_get_mac_addr_nvmem(struc
22 void *mac;
23 u8 nvmem_mac[ETH_ALEN];
24 struct platform_device *pdev = of_find_device_by_node(np);
25 + struct property *prop;
26
27 if (!pdev) {
28 *err = -ENODEV;
29 @@ -78,10 +79,29 @@ static void *of_get_mac_addr_nvmem(struc
30 put_device(&pdev->dev);
31 if (!mac) {
32 *err = -ENOMEM;
33 - return NULL;
34 + goto out_err;
35 + }
36 +
37 + prop = devm_kzalloc(&pdev->dev, sizeof(*prop), GFP_KERNEL);
38 + if (!prop) {
39 + *err = -ENOMEM;
40 + goto out_err;
41 + }
42 + prop->name = "mac-address";
43 + prop->length = ETH_ALEN;
44 + prop->value = devm_kmemdup(&pdev->dev, mac, ETH_ALEN, GFP_KERNEL);
45 + if (!prop->value || of_add_property(np, prop)) {
46 + *err = -ENOMEM;
47 + goto out_err;
48 }
49
50 return mac;
51 +
52 +out_err:
53 + devm_kfree(&pdev->dev, prop->value);
54 + devm_kfree(&pdev->dev, prop);
55 + devm_kfree(&pdev->dev, mac);
56 + return NULL;
57 }
58
59 static void *of_get_mac_address_mtd(struct device_node *np)