Re: [PATCH] rtc: spear: check return value of clk_enable in resume

From: Alexandre Belloni

Date: Sun Apr 12 2026 - 17:33:56 EST


On 01/03/2026 16:19:58+0000, Zhaoyang Yu wrote:
> In spear_rtc_resume(), the return value of clk_enable() is currently
> ignored. If clk_enable() fails, the driver proceeds to call
> spear_rtc_enable_interrupt().
>
> The spear_rtc_enable_interrupt() function performs a readl() on the
> RTC control register (CTRL_REG) as its first operation. Accessing an
> MMIO register of a peripheral without an enabled functional clock is
> unsafe on SPEAr architectures and can lead to a system hang or data
> abort.
>
> Fix this by checking the return value of clk_enable(). If it fails,
> print an error message and return the error code to avoid the unsafe
> register access.
>
> Signed-off-by: Zhaoyang Yu <2426767509@xxxxxx>
> ---
> drivers/rtc/rtc-spear.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
> index 959acff8faff..9bf7cf264715 100644
> --- a/drivers/rtc/rtc-spear.c
> +++ b/drivers/rtc/rtc-spear.c
> @@ -437,7 +437,7 @@ static int spear_rtc_resume(struct device *dev)
> {
> struct platform_device *pdev = to_platform_device(dev);
> struct spear_rtc_config *config = platform_get_drvdata(pdev);
> - int irq;
> + int irq, ret;
>
> irq = platform_get_irq(pdev, 0);
>
> @@ -447,7 +447,11 @@ static int spear_rtc_resume(struct device *dev)
> config->irq_wake = 0;
> }
> } else {
> - clk_enable(config->clk);

On spear, this function will never fail as this ultimately calls static
void clk_gate_endisable.

> + ret = clk_enable(config->clk);
> + if (ret) {
> + dev_err(dev, "Unable to enable clock on resume: %d\n", ret);
> + return ret;
> + }
> spear_rtc_enable_interrupt(config);
> }
>
> --
> 2.34.1
>

--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com