From: Jerome Brunet <jbrunet@baylibre.com>
To: Junhui Liu <junhui.liu@pigmoral.tech>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Maxime Ripard <mripard@kernel.org>
Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-clk@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
Jerome Brunet <jbrunet@baylibre.com>
Subject: [PATCH v3 3/8] clk: sunxi-ng: fix ccu probe clock unregister on error
Date: Thu, 02 Jul 2026 10:10:02 +0200 [thread overview]
Message-ID: <20260702-a733-rtc-v3-3-eb2580374de6@baylibre.com> (raw)
In-Reply-To: <20260702-a733-rtc-v3-0-eb2580374de6@baylibre.com>
When registering clocks with sunxi_ccu_probe(), the number of ccu_clocks
and the number of hw clocks might be different, eventhough they usually are
the same.
If they are different, it could lead to out-of-bound access or registered
clock left behind on error.
Use a different variable when iterating on hw clocks so every registered
clock, and only those, gets unregistered on error.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/r/20260629131254.7E34C1F00A3A@smtp.kernel.org
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
drivers/clk/sunxi-ng/ccu_common.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
index 1c083b4d0b7e..43d8eca6abee 100644
--- a/drivers/clk/sunxi-ng/ccu_common.c
+++ b/drivers/clk/sunxi-ng/ccu_common.c
@@ -114,7 +114,7 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
const struct sunxi_ccu_desc *desc)
{
struct ccu_reset *reset;
- int i, ret;
+ int i, j, ret;
ccu->desc = desc;
@@ -130,8 +130,8 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
cclk->lock = &ccu->lock;
}
- for (i = 0; i < desc->hw_clks->num ; i++) {
- struct clk_hw *hw = desc->hw_clks->hws[i];
+ for (j = 0; j < desc->hw_clks->num ; j++) {
+ struct clk_hw *hw = desc->hw_clks->hws[j];
const char *name;
if (!hw)
@@ -143,7 +143,7 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
else
ret = of_clk_hw_register(node, hw);
if (ret) {
- pr_err("Couldn't register clock %d - %s\n", i, name);
+ pr_err("Couldn't register clock %d - %s\n", j, name);
goto err_clk_unreg;
}
}
@@ -186,8 +186,8 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
err_del_provider:
of_clk_del_provider(node);
err_clk_unreg:
- while (--i >= 0) {
- struct clk_hw *hw = desc->hw_clks->hws[i];
+ while (--j >= 0) {
+ struct clk_hw *hw = desc->hw_clks->hws[j];
if (!hw)
continue;
--
2.47.3
next prev parent reply other threads:[~2026-07-02 8:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 8:09 [PATCH v3 0/8] clk: sun6i-rtc: Add support for Allwinner A733 SoC Jerome Brunet
2026-07-02 8:10 ` [PATCH v3 1/8] dt-bindings: rtc: sun6i: no clock-output-names on h616/r329 Jerome Brunet
2026-07-02 13:23 ` Chen-Yu Tsai
2026-07-02 18:44 ` Conor Dooley
2026-07-02 8:10 ` [PATCH v3 2/8] dt-bindings: rtc: sun6i: add sun60i-a733 support Jerome Brunet
2026-07-02 18:45 ` Conor Dooley
2026-07-02 8:10 ` Jerome Brunet [this message]
2026-07-02 13:23 ` [PATCH v3 3/8] clk: sunxi-ng: fix ccu probe clock unregister on error Chen-Yu Tsai
2026-07-02 8:10 ` [PATCH v3 4/8] clk: sunxi-ng: sun6i-rtc: clean up DT usage Jerome Brunet
2026-07-02 8:10 ` [PATCH v3 5/8] clk: sunxi-ng: sun6i-rtc: Add feature bit for IOSC calibration Jerome Brunet
2026-07-02 8:10 ` [PATCH v3 6/8] clk: sunxi-ng: div: add read-only operation support Jerome Brunet
2026-07-02 8:10 ` [PATCH v3 7/8] clk: sunxi-ng: sun6i-rtc: split main oscillator div and gate Jerome Brunet
2026-07-02 8:10 ` [PATCH v3 8/8] clk: sunxi-ng: sun6i-rtc: add a733 support Jerome Brunet
2026-07-02 23:59 ` [PATCH v3 0/8] clk: sun6i-rtc: Add support for Allwinner A733 SoC Enzo Adriano
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=20260702-a733-rtc-v3-3-eb2580374de6@baylibre.com \
--to=jbrunet@baylibre.com \
--cc=alexandre.belloni@bootlin.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=junhui.liu@pigmoral.tech \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=mripard@kernel.org \
--cc=mturquette@baylibre.com \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=sashiko-bot@kernel.org \
--cc=sboyd@kernel.org \
--cc=wens@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox