From: Pablo Mazzini <pmazzini@gmail.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Chen-Yu Tsai <wens@csie.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Maxime Ripard <mripard@kernel.org>, Rob Herring <robh@kernel.org>,
linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
Pablo Mazzini <pmazzini@gmail.com>
Subject: [PATCH] rtc: sun6i: fix error handling in sun6i_rtc_clk_init()
Date: Wed, 14 Oct 2026 20:32:20 +0100 [thread overview]
Message-ID: <20261014193220.38055-1-pmazzini@gmail.com> (raw)
Set sun6i_rtc only once all clocks are registered, and unwind fully on
error.
Signed-off-by: Pablo Mazzini <pmazzini@gmail.com>
---
drivers/rtc/rtc-sun6i.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index 7fc60880e409..dd293e8324b8 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -231,6 +231,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node,
const char *iosc_name = "rtc-int-osc";
const char *clkout_name = "osc32k-out";
const char *parents[2];
+ struct resource res;
u32 reg;
rtc = kzalloc_obj(*rtc);
@@ -267,9 +268,6 @@ static void __init sun6i_rtc_clk_init(struct device_node *node,
}
writel(reg, rtc->base + SUN6I_LOSC_CTRL);
- /* Yes, I know, this is ugly. */
- sun6i_rtc = rtc;
-
of_property_read_string_index(node, "clock-output-names", 2,
&iosc_name);
@@ -280,7 +278,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node,
300000000);
if (IS_ERR(rtc->int_osc)) {
pr_crit("Couldn't register the internal oscillator\n");
- goto err;
+ goto err_unmap;
}
parents[0] = clk_hw_get_name(rtc->int_osc);
@@ -309,7 +307,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node,
&rtc->lock);
if (IS_ERR(rtc->ext_losc)) {
pr_crit("Couldn't register the LOSC external gate\n");
- goto err_register;
+ goto err_losc;
}
clk_data->num = 3;
@@ -317,12 +315,22 @@ static void __init sun6i_rtc_clk_init(struct device_node *node,
clk_data->hws[1] = __clk_get_hw(rtc->ext_losc);
clk_data->hws[2] = rtc->int_osc;
of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
+
+ /* Yes, I know, this is ugly. */
+ sun6i_rtc = rtc;
return;
+err_losc:
+ clk_unregister(rtc->losc);
err_register:
clk_hw_unregister_fixed_rate(rtc->int_osc);
+err_unmap:
+ iounmap(rtc->base);
+ of_address_to_resource(node, 0, &res);
+ release_mem_region(res.start, resource_size(&res));
err:
kfree(clk_data);
+ kfree(rtc);
}
static const struct sun6i_rtc_clk_data sun6i_a31_rtc_data = {
--
2.52.0
reply other threads:[~2026-10-14 19:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261014193220.38055-1-pmazzini@gmail.com \
--to=pmazzini@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=mripard@kernel.org \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=wens@csie.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