[PATCH] rtc: spear: check return value of clk_enable in resume
From: Zhaoyang Yu
Date: Sun Mar 01 2026 - 11:24:15 EST
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);
+ 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