All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: <mturquette@baylibre.com>, <sboyd@kernel.org>,
	<luca.ceresoli@bootlin.com>, <nm@ti.com>, <kristo@kernel.org>,
	<ssantosh@kernel.org>, <michal.simek@xilinx.com>
Cc: <aford173@gmail.com>, <mike.looijmans@topic.nl>,
	<robert.hancock@calian.com>, <shawn.guo@linaro.org>,
	<fabio.estevam@freescale.com>, <linux-clk@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-omap@vger.kernel.org>,
	Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH 3/8] clk: si5341: return error if one synth clock registration fails
Date: Tue, 30 May 2023 12:39:08 +0300	[thread overview]
Message-ID: <20230530093913.1656095-4-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <20230530093913.1656095-1-claudiu.beznea@microchip.com>

In case devm_clk_hw_register() fails for one of synth clocks the probe
continues. Later on, when registering output clocks which have as parents
all the synth clocks, in case there is registration failure for at least
one synth clock the information passed to clk core for registering output
clock is not right: init.num_parents is fixed but init.parents may contain
an array with less parents.

Fixes: 3044a860fd09 ("clk: Add Si5341/Si5340 driver")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/clk/clk-si5341.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
index 0e528d7ba656..6dca3288c894 100644
--- a/drivers/clk/clk-si5341.c
+++ b/drivers/clk/clk-si5341.c
@@ -1553,7 +1553,7 @@ static int si5341_probe(struct i2c_client *client)
 	struct clk_init_data init;
 	struct clk *input;
 	const char *root_clock_name;
-	const char *synth_clock_names[SI5341_NUM_SYNTH];
+	const char *synth_clock_names[SI5341_NUM_SYNTH] = { NULL };
 	int err;
 	unsigned int i;
 	struct clk_si5341_output_config config[SI5341_MAX_NUM_OUTPUTS];
@@ -1705,6 +1705,7 @@ static int si5341_probe(struct i2c_client *client)
 		if (err) {
 			dev_err(&client->dev,
 				"synth N%u registration failed\n", i);
+			goto free_clk_names;
 		}
 	}
 
@@ -1782,16 +1783,17 @@ static int si5341_probe(struct i2c_client *client)
 		goto cleanup;
 	}
 
+free_clk_names:
 	/* Free the names, clk framework makes copies */
 	for (i = 0; i < data->num_synth; ++i)
 		 devm_kfree(&client->dev, (void *)synth_clock_names[i]);
 
-	return 0;
-
 cleanup:
-	for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
-		if (data->clk[i].vddo_reg)
-			regulator_disable(data->clk[i].vddo_reg);
+	if (err) {
+		for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
+			if (data->clk[i].vddo_reg)
+				regulator_disable(data->clk[i].vddo_reg);
+		}
 	}
 	return err;
 }
-- 
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: <mturquette@baylibre.com>, <sboyd@kernel.org>,
	<luca.ceresoli@bootlin.com>, <nm@ti.com>, <kristo@kernel.org>,
	<ssantosh@kernel.org>, <michal.simek@xilinx.com>
Cc: <aford173@gmail.com>, <mike.looijmans@topic.nl>,
	<robert.hancock@calian.com>, <shawn.guo@linaro.org>,
	<fabio.estevam@freescale.com>, <linux-clk@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-omap@vger.kernel.org>,
	Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH 3/8] clk: si5341: return error if one synth clock registration fails
Date: Tue, 30 May 2023 12:39:08 +0300	[thread overview]
Message-ID: <20230530093913.1656095-4-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <20230530093913.1656095-1-claudiu.beznea@microchip.com>

In case devm_clk_hw_register() fails for one of synth clocks the probe
continues. Later on, when registering output clocks which have as parents
all the synth clocks, in case there is registration failure for at least
one synth clock the information passed to clk core for registering output
clock is not right: init.num_parents is fixed but init.parents may contain
an array with less parents.

Fixes: 3044a860fd09 ("clk: Add Si5341/Si5340 driver")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
 drivers/clk/clk-si5341.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
index 0e528d7ba656..6dca3288c894 100644
--- a/drivers/clk/clk-si5341.c
+++ b/drivers/clk/clk-si5341.c
@@ -1553,7 +1553,7 @@ static int si5341_probe(struct i2c_client *client)
 	struct clk_init_data init;
 	struct clk *input;
 	const char *root_clock_name;
-	const char *synth_clock_names[SI5341_NUM_SYNTH];
+	const char *synth_clock_names[SI5341_NUM_SYNTH] = { NULL };
 	int err;
 	unsigned int i;
 	struct clk_si5341_output_config config[SI5341_MAX_NUM_OUTPUTS];
@@ -1705,6 +1705,7 @@ static int si5341_probe(struct i2c_client *client)
 		if (err) {
 			dev_err(&client->dev,
 				"synth N%u registration failed\n", i);
+			goto free_clk_names;
 		}
 	}
 
@@ -1782,16 +1783,17 @@ static int si5341_probe(struct i2c_client *client)
 		goto cleanup;
 	}
 
+free_clk_names:
 	/* Free the names, clk framework makes copies */
 	for (i = 0; i < data->num_synth; ++i)
 		 devm_kfree(&client->dev, (void *)synth_clock_names[i]);
 
-	return 0;
-
 cleanup:
-	for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
-		if (data->clk[i].vddo_reg)
-			regulator_disable(data->clk[i].vddo_reg);
+	if (err) {
+		for (i = 0; i < SI5341_MAX_NUM_OUTPUTS; ++i) {
+			if (data->clk[i].vddo_reg)
+				regulator_disable(data->clk[i].vddo_reg);
+		}
 	}
 	return err;
 }
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-05-30  9:40 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  9:39 [PATCH 0/8] clk: check memory returned by {devm_}kasprintf() Claudiu Beznea
2023-05-30  9:39 ` Claudiu Beznea
2023-05-30  9:39 ` [PATCH 1/8] clk: vc5: check memory returned by kasprintf() Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-05-31 16:32   ` Luca Ceresoli
2023-05-31 16:32     ` Luca Ceresoli
2023-06-20 18:53   ` Stephen Boyd
2023-06-20 18:53     ` Stephen Boyd
2023-05-30  9:39 ` [PATCH 2/8] clk: cdce925: check return value of kasprintf() Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-06-20 18:54   ` Stephen Boyd
2023-06-20 18:54     ` Stephen Boyd
2023-05-30  9:39 ` Claudiu Beznea [this message]
2023-05-30  9:39   ` [PATCH 3/8] clk: si5341: return error if one synth clock registration fails Claudiu Beznea
2023-06-20 18:54   ` Stephen Boyd
2023-06-20 18:54     ` Stephen Boyd
2023-05-30  9:39 ` [PATCH 4/8] clk: si5341: check return value of {devm_}kasprintf() Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-06-20 18:54   ` Stephen Boyd
2023-06-20 18:54     ` Stephen Boyd
2023-05-30  9:39 ` [PATCH 5/8] clk: si5341: free unused memory on probe failure Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-06-20 18:55   ` Stephen Boyd
2023-06-20 18:55     ` Stephen Boyd
2023-05-30  9:39 ` [PATCH 6/8] clk: keystone: sci-clk: check return value of kasprintf() Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-05-31  4:12   ` Tony Lindgren
2023-05-31  4:12     ` Tony Lindgren
2023-06-20 18:55   ` Stephen Boyd
2023-06-20 18:55     ` Stephen Boyd
2023-05-30  9:39 ` [PATCH 7/8] clk: ti: clkctrl: " Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-05-31  4:12   ` Tony Lindgren
2023-05-31  4:12     ` Tony Lindgren
2023-06-20 18:55   ` Stephen Boyd
2023-06-20 18:55     ` Stephen Boyd
2023-05-30  9:39 ` [PATCH 8/8] clk: clocking-wizard: check return value of devm_kasprintf() Claudiu Beznea
2023-05-30  9:39   ` Claudiu Beznea
2023-06-20 18:55   ` Stephen Boyd
2023-06-20 18:55     ` Stephen Boyd

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=20230530093913.1656095-4-claudiu.beznea@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=aford173@gmail.com \
    --cc=fabio.estevam@freescale.com \
    --cc=kristo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=michal.simek@xilinx.com \
    --cc=mike.looijmans@topic.nl \
    --cc=mturquette@baylibre.com \
    --cc=nm@ti.com \
    --cc=robert.hancock@calian.com \
    --cc=sboyd@kernel.org \
    --cc=shawn.guo@linaro.org \
    --cc=ssantosh@kernel.org \
    /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.