[PATCH v2 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path
From: Lee Jones
Date: Wed Dec 02 2026 - 15:23:17 EST
omap_rtc_power_off_program() is exported and called directly from
am33xx_rtc_only_idle() during suspend without checking whether
omap_rtc_power_off_rtc is NULL, causing a NULL pointer dereference if
omap_rtc_power_off_rtc was never assigned or was cleared on unbind.
Furthermore, omap_rtc_remove() only clears omap_rtc_power_off_rtc if
pm_power_off still equals omap_rtc_power_off; if another driver
overwrote pm_power_off after probe, unbinding the RTC leaves
omap_rtc_power_off_rtc pointing to freed memory for subsequent calls to
omap_rtc_power_off_program().
Return -ENODEV from omap_rtc_power_off_program() when
omap_rtc_power_off_rtc is NULL, and always clear omap_rtc_power_off_rtc
when removing the matching RTC instance.
Fixes: 5a99ae0092fe ("soc: ti: pm33xx: AM437X: Add rtc_only with ddr in self-refresh support")
Closes: https://sashiko.dev/#/bug/linux-97b795c5-f68f-4228-948f-547a106c6775
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
v1 => v2:
- Update Fixes: tag to 5a99ae0092fe ("soc: ti: pm33xx: AM437X: Add
rtc_only with ddr in self-refresh support") and reword the commit
message accordingly (Johan)
- Drop the unrelated refactoring in omap_rtc_power_off() (Johan)
Cc: "George G. Davis" <gdavis@xxxxxxxxxx>
Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
Cc: Dave Gerlach <d-gerlach@xxxxxx>
Cc: Johan Hovold <johan@xxxxxxxxxx>
Cc: Keerthy <j-keerthy@xxxxxx>
Cc: linux-rtc@xxxxxxxxxxxxxxx
Cc: Tony Lindgren <tony@xxxxxxxxxxx>
drivers/rtc/rtc-omap.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 18492165a19f..f75a00dd8386 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -416,6 +416,9 @@ int omap_rtc_power_off_program(void)
int seconds;
u32 val;
+ if (!rtc)
+ return -ENODEV;
+
rtc->type->unlock(rtc);
/* enable pmic_power_en control */
val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
@@ -913,9 +916,9 @@ static void omap_rtc_remove(struct platform_device *pdev)
struct omap_rtc *rtc = platform_get_drvdata(pdev);
u8 reg;
- if (pm_power_off == omap_rtc_power_off &&
- omap_rtc_power_off_rtc == rtc) {
- pm_power_off = NULL;
+ if (omap_rtc_power_off_rtc == rtc) {
+ if (pm_power_off == omap_rtc_power_off)
+ pm_power_off = NULL;
omap_rtc_power_off_rtc = NULL;
}
--
2.56.1.911.g883d8bcb20-goog