of_net: remove nvmem-mac-address property
authorPetr Štetiar <ynezz@true.cz>
Fri, 10 May 2019 09:35:14 +0000 (11:35 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 May 2019 22:14:29 +0000 (15:14 -0700)
In commit d01f449c008a ("of_net: add NVMEM support to
of_get_mac_address") I've added `nvmem-mac-address` property which was
wrong idea as I've allocated the property with devm_kzalloc and then
added it to DT, so then 2 entities would be refcounting the allocation.
So if the driver unbinds, the buffer is freed, but DT code would be
still referencing that memory.

I'm removing this property completely instead of fixing it, as it's not
needed to have it.

Fixes: d01f449c008a ("of_net: add NVMEM support to of_get_mac_address")
Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/of/of_net.c

index 9649cd53e95574a26a61b65bc587788ab19846e6..a4b392a5406b2c546312e81d2e0707fae4045482 100644 (file)
@@ -52,39 +52,22 @@ static const void *of_get_mac_addr(struct device_node *np, const char *name)
 static const void *of_get_mac_addr_nvmem(struct device_node *np)
 {
        int ret;
-       u8 mac[ETH_ALEN];
-       struct property *pp;
+       const void *mac;
+       u8 nvmem_mac[ETH_ALEN];
        struct platform_device *pdev = of_find_device_by_node(np);
 
        if (!pdev)
                return ERR_PTR(-ENODEV);
 
-       ret = nvmem_get_mac_address(&pdev->dev, &mac);
+       ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
        if (ret)
                return ERR_PTR(ret);
 
-       pp = devm_kzalloc(&pdev->dev, sizeof(*pp), GFP_KERNEL);
-       if (!pp)
+       mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
+       if (!mac)
                return ERR_PTR(-ENOMEM);
 
-       pp->name = "nvmem-mac-address";
-       pp->length = ETH_ALEN;
-       pp->value = devm_kmemdup(&pdev->dev, mac, ETH_ALEN, GFP_KERNEL);
-       if (!pp->value) {
-               ret = -ENOMEM;
-               goto free;
-       }
-
-       ret = of_add_property(np, pp);
-       if (ret)
-               goto free;
-
-       return pp->value;
-free:
-       devm_kfree(&pdev->dev, pp->value);
-       devm_kfree(&pdev->dev, pp);
-
-       return ERR_PTR(ret);
+       return mac;
 }
 
 /**