2019-05-13 10:23:30

by Petr Štetiar

[permalink] [raw]
Subject: [PATCH] of_net: Fix missing of_find_device_by_node ref count drop

of_find_device_by_node takes a reference to the embedded struct device
which needs to be dropped after use.

Fixes: d01f449c008a ("of_net: add NVMEM support to of_get_mac_address")
Reported-by: kbuild test robot <[email protected]>
Reported-by: Julia Lawall <[email protected]>
Signed-off-by: Petr Štetiar <[email protected]>
---
drivers/of/of_net.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index a4b392a5406b..6f1be80e8c4e 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -60,10 +60,13 @@ static const void *of_get_mac_addr_nvmem(struct device_node *np)
return ERR_PTR(-ENODEV);

ret = nvmem_get_mac_address(&pdev->dev, &nvmem_mac);
- if (ret)
+ if (ret) {
+ put_device(&pdev->dev);
return ERR_PTR(ret);
+ }

mac = devm_kmemdup(&pdev->dev, nvmem_mac, ETH_ALEN, GFP_KERNEL);
+ put_device(&pdev->dev);
if (!mac)
return ERR_PTR(-ENOMEM);

--
1.9.1


2019-05-13 15:37:27

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH] of_net: Fix missing of_find_device_by_node ref count drop

On Mon, May 13, 2019 at 11:41:39AM +0200, Petr Štetiar wrote:
> of_find_device_by_node takes a reference to the embedded struct device
> which needs to be dropped after use.
>
> Fixes: d01f449c008a ("of_net: add NVMEM support to of_get_mac_address")
> Reported-by: kbuild test robot <[email protected]>
> Reported-by: Julia Lawall <[email protected]>
> Signed-off-by: Petr Štetiar <[email protected]>

Reviewed-by: Andrew Lunn <[email protected]>

Andrew

2019-05-13 16:57:43

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] of_net: Fix missing of_find_device_by_node ref count drop

From: Petr ?tetiar <[email protected]>
Date: Mon, 13 May 2019 11:41:39 +0200

> of_find_device_by_node takes a reference to the embedded struct device
> which needs to be dropped after use.
>
> Fixes: d01f449c008a ("of_net: add NVMEM support to of_get_mac_address")
> Reported-by: kbuild test robot <[email protected]>
> Reported-by: Julia Lawall <[email protected]>
> Signed-off-by: Petr ?tetiar <[email protected]>

Applied, thank you.