From 2d6f97296143a97653e03a1b2517c554b0950f20 Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Wed, 14 Oct 2026 20:32:20 +0100 Subject: [PATCH] rtc: sun6i: fix error handling in sun6i_rtc_clk_init() Set sun6i_rtc only once all clocks are registered, and unwind fully on error. Signed-off-by: Pablo Mazzini Link: https://patch.msgid.link/20261014193220.38055-1-pmazzini@gmail.com Signed-off-by: Alexandre Belloni --- 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 = {