summaryrefslogtreecommitdiff
path: root/drivers/clk
diff options
context:
space:
mode:
authorJoe Hattori <joe@pf.is.s.u-tokyo.ac.jp>2024-12-10 22:09:12 +0900
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-02-08 09:57:03 +0100
commite561d1a2ba3a32e54432d323352e87fc55eb6829 (patch)
treeeed3e7ea7e8cd969e2c96e16ff49b4c31d4ef0a2 /drivers/clk
parent712b9797e45a08059e30793072f9ba7e7d37024c (diff)
downloadlinux-e561d1a2ba3a32e54432d323352e87fc55eb6829.tar.gz
linux-e561d1a2ba3a32e54432d323352e87fc55eb6829.tar.bz2
linux-e561d1a2ba3a32e54432d323352e87fc55eb6829.zip
clk: fix an OF node reference leak in of_clk_get_parent_name()
[ Upstream commit 28fa3291cad1c201967ef93edc6e7f8ccc9afbc0 ] 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> 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/clk.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index d02451f951cf..5b4ab94193c2 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -5391,8 +5391,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,