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 <pmazzini@gmail.com>
Link: https://patch.msgid.link/20261014193220.38055-1-pmazzini@gmail.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
Pablo Mazzini 2026-10-14 20:32:20 +01:00 committed by Alexandre Belloni
parent 3c7acb209e
commit 2d6f972961

View File

@ -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 = {