Skip to content

Commit 28fa329

Browse files
joehattoribebarino
authored andcommitted
clk: fix an OF node reference leak in of_clk_get_parent_name()
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: 8da411c ("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> Link: https://lore.kernel.org/r/20241210130913.3615205-1-joe@pf.is.s.u-tokyo.ac.jp Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent e5ca5d7 commit 28fa329

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/clk/clk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5385,8 +5385,10 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index)
53855385
count++;
53865386
}
53875387
/* We went off the end of 'clock-indices' without finding it */
5388-
if (of_property_present(clkspec.np, "clock-indices") && !found)
5388+
if (of_property_present(clkspec.np, "clock-indices") && !found) {
5389+
of_node_put(clkspec.np);
53895390
return NULL;
5391+
}
53905392

53915393
if (of_property_read_string_index(clkspec.np, "clock-output-names",
53925394
index,

0 commit comments

Comments
 (0)