linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] versatile clock: Adjustments for two function implementations
@ 2024-01-17 17:40 Markus Elfring
  2024-01-17 17:41 ` [PATCH 1/2] clk: versatile: clk-icst: Return directly after a failed kasprintf() call in of_syscon_icst_setup() Markus Elfring
  2024-01-17 17:42 ` [PATCH 2/2] clk: versatile: clk-icst: Use common error handling code in icst_clk_setup() Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2024-01-17 17:40 UTC (permalink / raw)
  To: linux-clk, kernel-janitors, linux-arm-kernel, Linus Walleij,
	Michael Turquette, Rob Herring, Stephen Boyd
  Cc: LKML, Kunwu Chan

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 17 Jan 2024 18:30:08 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Return directly after a failed kasprintf() call in of_syscon_icst_setup()
  Use common error handling code in icst_clk_setup()

 drivers/clk/versatile/clk-icst.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

--
2.43.0


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

* [PATCH 1/2] clk: versatile: clk-icst: Return directly after a failed kasprintf() call in of_syscon_icst_setup()
  2024-01-17 17:40 [PATCH 0/2] versatile clock: Adjustments for two function implementations Markus Elfring
@ 2024-01-17 17:41 ` Markus Elfring
  2024-01-17 17:42 ` [PATCH 2/2] clk: versatile: clk-icst: Use common error handling code in icst_clk_setup() Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-01-17 17:41 UTC (permalink / raw)
  To: linux-clk, kernel-janitors, linux-arm-kernel, Linus Walleij,
	Michael Turquette, Rob Herring, Stephen Boyd
  Cc: LKML, Kunwu Chan

From: Markus Elfring <elfring@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@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


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

* [PATCH 2/2] clk: versatile: clk-icst: Use common error handling code in icst_clk_setup()
  2024-01-17 17:40 [PATCH 0/2] versatile clock: Adjustments for two function implementations Markus Elfring
  2024-01-17 17:41 ` [PATCH 1/2] clk: versatile: clk-icst: Return directly after a failed kasprintf() call in of_syscon_icst_setup() Markus Elfring
@ 2024-01-17 17:42 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-01-17 17:42 UTC (permalink / raw)
  To: linux-clk, kernel-janitors, linux-arm-kernel, Linus Walleij,
	Michael Turquette, Rob Herring, Stephen Boyd
  Cc: LKML, Kunwu Chan

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

Add a jump target so that a bit of exception handling can be better reused
in an if branch of this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/clk/versatile/clk-icst.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c
index c4cf50a48972..9957dc9b8941 100644
--- a/drivers/clk/versatile/clk-icst.c
+++ b/drivers/clk/versatile/clk-icst.c
@@ -351,8 +351,8 @@ struct clk *icst_clk_setup(struct device *dev,

 	pclone = kmemdup(desc->params, sizeof(*pclone), GFP_KERNEL);
 	if (!pclone) {
-		kfree(icst);
-		return ERR_PTR(-ENOMEM);
+		clk = ERR_PTR(-ENOMEM);
+		goto free_icst;
 	}

 	init.name = name;
@@ -370,6 +370,7 @@ struct clk *icst_clk_setup(struct device *dev,
 	clk = clk_register(dev, &icst->hw);
 	if (IS_ERR(clk)) {
 		kfree(pclone);
+free_icst:
 		kfree(icst);
 	}

--
2.43.0


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

end of thread, other threads:[~2024-01-17 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17 17:40 [PATCH 0/2] versatile clock: Adjustments for two function implementations Markus Elfring
2024-01-17 17:41 ` [PATCH 1/2] clk: versatile: clk-icst: Return directly after a failed kasprintf() call in of_syscon_icst_setup() Markus Elfring
2024-01-17 17:42 ` [PATCH 2/2] clk: versatile: clk-icst: Use common error handling code in icst_clk_setup() Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).