* [PATCH] of: unittest: Add of_node_put() before return
@ 2019-08-15 6:22 Nishka Dasgupta
2019-08-27 16:21 ` Rob Herring
0 siblings, 1 reply; 2+ messages in thread
From: Nishka Dasgupta @ 2019-08-15 6:22 UTC (permalink / raw)
To: robh+dt, frowand.list, devicetree; +Cc: Nishka Dasgupta
The local variable np in function of_unittest_platform_populate takes
the return value of of_find_node_by_path, which gets a node but does not
put it. If np is not put before return it may cause a memory leak. Hence
put np before a return statement.
Issue found with Coccinelle.
Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
drivers/of/unittest.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index e6b175370f2e..480a21e2ed39 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1044,8 +1044,10 @@ static void __init of_unittest_platform_populate(void)
test_bus = platform_device_register_full(&test_bus_info);
rc = PTR_ERR_OR_ZERO(test_bus);
unittest(!rc, "testbus registration failed; rc=%i\n", rc);
- if (rc)
+ if (rc) {
+ of_node_put(np);
return;
+ }
test_bus->dev.of_node = np;
/*
--
2.19.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] of: unittest: Add of_node_put() before return
2019-08-15 6:22 [PATCH] of: unittest: Add of_node_put() before return Nishka Dasgupta
@ 2019-08-27 16:21 ` Rob Herring
0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2019-08-27 16:21 UTC (permalink / raw)
To: Nishka Dasgupta; +Cc: robh+dt, frowand.list, devicetree
On Thu, 15 Aug 2019 11:52:18 +0530, Nishka Dasgupta wrote:
> The local variable np in function of_unittest_platform_populate takes
> the return value of of_find_node_by_path, which gets a node but does not
> put it. If np is not put before return it may cause a memory leak. Hence
> put np before a return statement.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
> drivers/of/unittest.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
Applied, thanks.
Rob
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-27 16:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-15 6:22 [PATCH] of: unittest: Add of_node_put() before return Nishka Dasgupta
2019-08-27 16:21 ` Rob Herring
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.