All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-omap@vger.kernel.org, linux-clk@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Michael Turquette <mturquette@baylibre.com>,
	Rob Herring <robh@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
	Tero Kristo <kristo@kernel.org>, Tony Lindgren <tony@atomide.com>
Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr
Subject: [PATCH 01/10] clk: ti: Less function calls in of_omap2_apll_setup() after error detection
Date: Sun, 24 Dec 2023 17:36:57 +0100	[thread overview]
Message-ID: <422c6249-31ac-410e-911d-ec25aeee126a@web.de> (raw)
In-Reply-To: <20849a8e-e0f5-46df-ad8a-9eae6cbe337b@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 24 Dec 2023 11:15:27 +0100

The kfree() function was called in up to three cases by
the of_omap2_apll_setup() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

* Split a condition check.

* Adjust jump targets.

* Delete three initialisations which became unnecessary
  with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/clk/ti/apll.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/ti/apll.c b/drivers/clk/ti/apll.c
index 93183287c58d..929c021f0cdb 100644
--- a/drivers/clk/ti/apll.c
+++ b/drivers/clk/ti/apll.c
@@ -338,21 +338,25 @@ static const struct clk_hw_omap_ops omap2_apll_hwops = {

 static void __init of_omap2_apll_setup(struct device_node *node)
 {
-	struct dpll_data *ad = NULL;
-	struct clk_hw_omap *clk_hw = NULL;
-	struct clk_init_data *init = NULL;
+	struct dpll_data *ad;
+	struct clk_hw_omap *clk_hw;
+	struct clk_init_data *init = kzalloc(sizeof(*init), GFP_KERNEL);
 	const char *name;
 	struct clk *clk;
 	const char *parent_name;
 	u32 val;
 	int ret;

-	ad = kzalloc(sizeof(*ad), GFP_KERNEL);
+	if (!init)
+		return;
+
 	clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
-	init = kzalloc(sizeof(*init), GFP_KERNEL);
+	if (!clk_hw)
+		goto free_init;

-	if (!ad || !clk_hw || !init)
-		goto cleanup;
+	ad = kzalloc(sizeof(*ad), GFP_KERNEL);
+	if (!ad)
+		goto free_clk_hw;

 	clk_hw->dpll_data = ad;
 	clk_hw->hw.init = init;
@@ -403,12 +407,13 @@ static void __init of_omap2_apll_setup(struct device_node *node)
 	clk = of_ti_clk_register_omap_hw(node, &clk_hw->hw, name);
 	if (!IS_ERR(clk)) {
 		of_clk_add_provider(node, of_clk_src_simple_get, clk);
-		kfree(init);
-		return;
+		goto free_init;
 	}
 cleanup:
 	kfree(ad);
+free_clk_hw:
 	kfree(clk_hw);
+free_init:
 	kfree(init);
 }
 CLK_OF_DECLARE(omap2_apll_clock, "ti,omap2-apll-clock",
--
2.43.0


WARNING: multiple messages have this Message-ID (diff)
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-omap@vger.kernel.org, linux-clk@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Michael Turquette <mturquette@baylibre.com>,
	Rob Herring <robh@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
	Tero Kristo <kristo@kernel.org>, Tony Lindgren <tony@atomide.com>
Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr
Subject: [cocci] [PATCH 01/10] clk: ti: Less function calls in of_omap2_apll_setup() after error detection
Date: Sun, 24 Dec 2023 17:36:57 +0100	[thread overview]
Message-ID: <422c6249-31ac-410e-911d-ec25aeee126a@web.de> (raw)
In-Reply-To: <20849a8e-e0f5-46df-ad8a-9eae6cbe337b@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 24 Dec 2023 11:15:27 +0100

The kfree() function was called in up to three cases by
the of_omap2_apll_setup() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

* Split a condition check.

* Adjust jump targets.

* Delete three initialisations which became unnecessary
  with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/clk/ti/apll.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/ti/apll.c b/drivers/clk/ti/apll.c
index 93183287c58d..929c021f0cdb 100644
--- a/drivers/clk/ti/apll.c
+++ b/drivers/clk/ti/apll.c
@@ -338,21 +338,25 @@ static const struct clk_hw_omap_ops omap2_apll_hwops = {

 static void __init of_omap2_apll_setup(struct device_node *node)
 {
-	struct dpll_data *ad = NULL;
-	struct clk_hw_omap *clk_hw = NULL;
-	struct clk_init_data *init = NULL;
+	struct dpll_data *ad;
+	struct clk_hw_omap *clk_hw;
+	struct clk_init_data *init = kzalloc(sizeof(*init), GFP_KERNEL);
 	const char *name;
 	struct clk *clk;
 	const char *parent_name;
 	u32 val;
 	int ret;

-	ad = kzalloc(sizeof(*ad), GFP_KERNEL);
+	if (!init)
+		return;
+
 	clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
-	init = kzalloc(sizeof(*init), GFP_KERNEL);
+	if (!clk_hw)
+		goto free_init;

-	if (!ad || !clk_hw || !init)
-		goto cleanup;
+	ad = kzalloc(sizeof(*ad), GFP_KERNEL);
+	if (!ad)
+		goto free_clk_hw;

 	clk_hw->dpll_data = ad;
 	clk_hw->hw.init = init;
@@ -403,12 +407,13 @@ static void __init of_omap2_apll_setup(struct device_node *node)
 	clk = of_ti_clk_register_omap_hw(node, &clk_hw->hw, name);
 	if (!IS_ERR(clk)) {
 		of_clk_add_provider(node, of_clk_src_simple_get, clk);
-		kfree(init);
-		return;
+		goto free_init;
 	}
 cleanup:
 	kfree(ad);
+free_clk_hw:
 	kfree(clk_hw);
+free_init:
 	kfree(init);
 }
 CLK_OF_DECLARE(omap2_apll_clock, "ti,omap2-apll-clock",
--
2.43.0


  reply	other threads:[~2023-12-24 16:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-24 16:33 [cocci] [PATCH 00/10] clk: ti: Adjustments for eight function implementations Markus Elfring
2023-12-24 16:33 ` Markus Elfring
2023-12-24 16:36 ` Markus Elfring [this message]
2023-12-24 16:36   ` [cocci] [PATCH 01/10] clk: ti: Less function calls in of_omap2_apll_setup() after error detection Markus Elfring
2023-12-27 16:38   ` Andy Shevchenko
2023-12-24 16:38 ` [PATCH 02/10] clk: ti: Less function calls in of_dra7_apll_setup() " Markus Elfring
2023-12-24 16:38   ` [cocci] " Markus Elfring
2023-12-24 16:40 ` [cocci] [PATCH 03/10] clk: ti: Use common code in omap_clk_register_apll() Markus Elfring
2023-12-24 16:40   ` Markus Elfring
2023-12-24 16:42 ` [PATCH 04/10] clk: ti: Less function calls in ti_fapll_setup() after error detection Markus Elfring
2023-12-24 16:42   ` [cocci] " Markus Elfring
2023-12-24 16:44 ` [cocci] [PATCH 05/10] clk: ti: One function call less in ti_fapll_synth_setup() " Markus Elfring
2023-12-24 16:44   ` Markus Elfring
2023-12-24 16:45 ` [PATCH 06/10] clk: ti: Return directly after a failed kzalloc() in of_mux_clk_setup() Markus Elfring
2023-12-24 16:45   ` [cocci] " Markus Elfring
2023-12-24 16:47 ` [PATCH 07/10] clk: ti: Less function calls in _ti_omap4_clkctrl_setup() after error detection Markus Elfring
2023-12-24 16:47   ` [cocci] " Markus Elfring
2023-12-24 16:48 ` [PATCH 08/10] clk: ti: Use common error handling code in _ti_omap4_clkctrl_setup() Markus Elfring
2023-12-24 16:48   ` [cocci] " Markus Elfring
2023-12-24 16:50 ` [PATCH 09/10] clk: ti: Less function calls in _ti_clkctrl_clk_register() after error detection Markus Elfring
2023-12-24 16:50   ` [cocci] " Markus Elfring
2023-12-28  5:18   ` kernel test robot
2023-12-28  6:39     ` [09/10] " Markus Elfring
2023-12-28  6:39       ` [cocci] " Markus Elfring
2023-12-24 16:52 ` [PATCH 10/10] clk: ti: Delete an unnecessary initialisation in _ti_clkctrl_clk_register() Markus Elfring
2023-12-24 16:52   ` [cocci] " Markus Elfring
2023-12-27 16:39 ` [PATCH 00/10] clk: ti: Adjustments for eight function implementations Andy Shevchenko
2024-02-20  9:27   ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=422c6249-31ac-410e-911d-ec25aeee126a@web.de \
    --to=markus.elfring@web.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=cocci@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kristo@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.