[PATCH 1/2] clk: versatile: clk-icst: Return directly after a failed kasprintf() call in of_syscon_icst_setup()

Markus Elfring Markus.Elfring at web.de
Wed Jan 17 09:41:47 PST 2024


From: Markus Elfring <elfring at users.sourceforge.net>
Date: Wed, 17 Jan 2024 18:06:55 +0100

The result from a call of the function “kasprintf” was passed to
a subsequent function call without checking for a null pointer before
(according to a memory allocation failure).
This issue was detected by using the Coccinelle software.

Thus return directly after a failed kasprintf() call.

Fixes: 1b2189f3aa50b ("clk: versatile: clk-icst: Ensure clock names are unique")
Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>
---
 drivers/clk/versatile/clk-icst.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c
index d5cb372f0901..c4cf50a48972 100644
--- a/drivers/clk/versatile/clk-icst.c
+++ b/drivers/clk/versatile/clk-icst.c
@@ -537,10 +537,12 @@ static void __init of_syscon_icst_setup(struct device_node *np)
 		return;
 	}

-	/* 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)
+		return;

+	/* Parent clock name is not the same as node parent */
+	parent_name = of_clk_get_parent_name(np, 0);
 	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);
--
2.43.0




More information about the linux-arm-kernel mailing list