[PATCH 10/10] clk: versatile: icst: Check kasprintf() and put parent node on error

Lee Jones lee at kernel.org
Fri Nov 27 11:25:34 PST 2026


of_syscon_icst_setup() does not check the return value of kasprintf()
before passing name into icst_clk_setup(), causing registration to fail
with -ENOMEM after redundant allocations and logging a NULL name while
leaking the parent device node reference.  The IS_ERR(regclk) error path
also omits of_node_put().

Release the parent node and return early when kasprintf() fails, and
release the parent node when icst_clk_setup() returns an error.

Fixes: 1b2189f3aa50 ("clk: versatile: clk-icst: Ensure clock names are unique")
Fixes: d430819d69a5 ("clk: versatile-icst: add device tree support")
Closes: https://sashiko.dev/#/bug/linux-e1f9fcba-856e-41f5-ba69-bf159007e2af
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
 drivers/clk/versatile/clk-icst.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c
index e9c7353aa5d5..10cb34a3e8ea 100644
--- a/drivers/clk/versatile/clk-icst.c
+++ b/drivers/clk/versatile/clk-icst.c
@@ -566,11 +566,16 @@ static void __init of_syscon_icst_setup(struct device_node *np)
 	/* Parent clock name is not the same as node parent */
 	parent_name = of_clk_get_parent_name(np, 0);
 	name = kasprintf(GFP_KERNEL, "%pOFP", np);
+	if (!name) {
+		of_node_put(parent);
+		return;
+	}
 
 	regclk = icst_clk_setup(NULL, &icst_desc, name, parent_name, map, ctype);
 	if (IS_ERR(regclk)) {
 		pr_err("error setting up syscon ICST clock %s\n", name);
 		kfree(name);
+		of_node_put(parent);
 		return;
 	}
 	of_clk_add_provider(np, of_clk_src_simple_get, regclk);
-- 
2.56.1.839.g22a8290db9-goog




More information about the linux-arm-kernel mailing list