linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: versatile: Add of_node_put() before return statement
@ 2020-08-29 17:57 Sumera Priyadarsini
  2020-08-30 10:07 ` Linus Walleij
  2020-09-10  7:57 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Sumera Priyadarsini @ 2020-08-29 17:57 UTC (permalink / raw)
  To: linus.walleij
  Cc: mturquette, sboyd, Julia.Lawall, linux-arm-kernel, linux-clk,
	linux-kernel

Every iteration of for_each_available_child_of_node() decrements
the reference count of the previous node, however when control is
transferred from the middle of the loop, as in the case of a return
or break or goto, there is no decrement thus ultimately resulting in
a memory leak.

Fix a potential memory leak in clk-impd1.c by inserting
of_node_put() before a return statement.

Issue found with Coccinelle.

Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com>
---
 drivers/clk/versatile/clk-impd1.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/versatile/clk-impd1.c b/drivers/clk/versatile/clk-impd1.c
index ca798249544d..85c395df9c00 100644
--- a/drivers/clk/versatile/clk-impd1.c
+++ b/drivers/clk/versatile/clk-impd1.c
@@ -109,8 +109,10 @@ static int integrator_impd1_clk_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(np, child) {
 		ret = integrator_impd1_clk_spawn(dev, np, child);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			break;
+		}
 	}
 
 	return ret;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: versatile: Add of_node_put() before return statement
  2020-08-29 17:57 [PATCH] clk: versatile: Add of_node_put() before return statement Sumera Priyadarsini
@ 2020-08-30 10:07 ` Linus Walleij
  2020-09-10  7:57 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2020-08-30 10:07 UTC (permalink / raw)
  To: Sumera Priyadarsini
  Cc: Michael Turquette, Stephen Boyd, Julia Lawall, Linux ARM,
	linux-clk, linux-kernel

On Sat, Aug 29, 2020 at 7:57 PM Sumera Priyadarsini
<sylphrenadin@gmail.com> wrote:

> Every iteration of for_each_available_child_of_node() decrements
> the reference count of the previous node, however when control is
> transferred from the middle of the loop, as in the case of a return
> or break or goto, there is no decrement thus ultimately resulting in
> a memory leak.
>
> Fix a potential memory leak in clk-impd1.c by inserting
> of_node_put() before a return statement.
>
> Issue found with Coccinelle.
>
> Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: versatile: Add of_node_put() before return statement
  2020-08-29 17:57 [PATCH] clk: versatile: Add of_node_put() before return statement Sumera Priyadarsini
  2020-08-30 10:07 ` Linus Walleij
@ 2020-09-10  7:57 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-09-10  7:57 UTC (permalink / raw)
  To: Sumera Priyadarsini, linus.walleij
  Cc: mturquette, Julia.Lawall, linux-arm-kernel, linux-clk, linux-kernel

Quoting Sumera Priyadarsini (2020-08-29 10:57:04)
> Every iteration of for_each_available_child_of_node() decrements
> the reference count of the previous node, however when control is
> transferred from the middle of the loop, as in the case of a return
> or break or goto, there is no decrement thus ultimately resulting in
> a memory leak.
> 
> Fix a potential memory leak in clk-impd1.c by inserting
> of_node_put() before a return statement.
> 
> Issue found with Coccinelle.
> 
> Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com>
> ---

Applied to clk-fixes

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-10  7:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-29 17:57 [PATCH] clk: versatile: Add of_node_put() before return statement Sumera Priyadarsini
2020-08-30 10:07 ` Linus Walleij
2020-09-10  7:57 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).