Skip to contentSkip to conversation

rtc: omap: wait for !BUSY before reading time for the power-off alarm

PATCH New Rosen Penev 2 participants 2 messages Oct 4 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: omap: wait for !BUSY before reading time for the power-off alarm

omap_rtc_power_off_program() reads the time registers to arm ALARM2 one second ahead, but does not wait for STATUS.BUSY to clear first, unlike omap_rtc_read_time(). The time registers must not be accessed while BUSY is set, as the counters may be partway through an update.

A read during an update can return, for example, seconds already wrapped to 0 with minutes still at the old value. The rollover check after arming only compares the seconds register, which no longer changes, so it passes and ALARM2 is armed for a time that has already passed. Power-off or rtc-only suspend then waits for an alarm that does not fire as intended.

Call rtc_wait_not_busy() before the read, as omap_rtc_read_time() does. Both callers run with local interrupts disabled, as the access window requires.

Fixes 222a12fca604 ("rtc: omap: add support for pmic_power_en")
Assisted-by LLM
---
 drivers/rtc/rtc-omap.c | 1 +
 1 file changed, 1 insertion(+)
drivers/rtc/rtc-omap.c +1 -0
index 540232d6f26c..4e9b4f601a9c 100644
@@ -437,6 +437,7 @@ int omap_rtc_power_off_program(void)
 	rtc_writel(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM2);
 
 	/* set alarm one second from now */
+	rtc_wait_not_busy(rtc);
 	omap_rtc_read_time_raw(rtc, &tm);
 	seconds = tm.tm_sec;
 	bcd2tm(&tm);
Signature · 1 line
2.56.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines

omap_rtc_power_off_program() reads the time registers to arm ALARM2 one second ahead, but does not wait for STATUS.BUSY to clear first, unlike omap_rtc_read_time(). The time registers must not be accessed while BUSY is set, as the counters may be partway through an update.

A read during an update can return, for example, seconds already wrapped to 0 with minutes still at the old value. The rollover check after arming only compares the seconds register, which no longer changes, so it passes and ALARM2 is armed for a time that has already passed. Power-off or rtc-only suspend then waits for an alarm that does not fire as intended.

Quoted 7 lines

Call rtc_wait_not_busy() before the read, as omap_rtc_read_time() does. Both callers run with local interrupts disabled, as the access window requires.

Fixes 222a12fca604 ("rtc: omap: add support for pmic_power_en")
Assisted-by LLM

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1