All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: fix an OF node reference leak in of_clk_get_parent_name()
@ 2024-12-10 13:09 Joe Hattori
  2024-12-10 22:54 ` Stephen Boyd
  0 siblings, 1 reply; 2+ messages in thread
From: Joe Hattori @ 2024-12-10 13:09 UTC (permalink / raw)
  To: mturquette, sboyd; +Cc: linux-clk, Joe Hattori

Current implementation of of_clk_get_parent_name() leaks an OF node
reference on error path. Add a of_node_put() call before returning an
error.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: 8da411cc1964 ("clk: let of_clk_get_parent_name() fail for invalid clock-indices")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/clk/clk.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index bdc6e5b90da5..cc57f3f5eb60 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -5385,8 +5385,10 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index)
 		count++;
 	}
 	/* We went off the end of 'clock-indices' without finding it */
-	if (of_property_present(clkspec.np, "clock-indices") && !found)
+	if (of_property_present(clkspec.np, "clock-indices") && !found) {
+		of_node_put(clkspec.np);
 		return NULL;
+	}
 
 	if (of_property_read_string_index(clkspec.np, "clock-output-names",
 					  index,
-- 
2.34.1


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

* Re: [PATCH] clk: fix an OF node reference leak in of_clk_get_parent_name()
  2024-12-10 13:09 [PATCH] clk: fix an OF node reference leak in of_clk_get_parent_name() Joe Hattori
@ 2024-12-10 22:54 ` Stephen Boyd
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2024-12-10 22:54 UTC (permalink / raw)
  To: Joe Hattori, mturquette; +Cc: linux-clk, Joe Hattori

Quoting Joe Hattori (2024-12-10 05:09:12)
> Current implementation of of_clk_get_parent_name() leaks an OF node
> reference on error path. Add a of_node_put() call before returning an
> error.
> 
> This bug was found by an experimental static analysis tool that I am
> developing.
> 
> Fixes: 8da411cc1964 ("clk: let of_clk_get_parent_name() fail for invalid clock-indices")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---

Applied to clk-next

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

end of thread, other threads:[~2024-12-10 22:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-10 13:09 [PATCH] clk: fix an OF node reference leak in of_clk_get_parent_name() Joe Hattori
2024-12-10 22:54 ` Stephen Boyd

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.