diff --git a/components/drivers/rtc/dev_alarm.c b/components/drivers/rtc/dev_alarm.c index 48a03ea9a361..4752627bc234 100644 --- a/components/drivers/rtc/dev_alarm.c +++ b/components/drivers/rtc/dev_alarm.c @@ -149,9 +149,13 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now) break; case RT_ALARM_MINUTE: { - alarm->wktime.tm_hour = now->tm_hour; - if (alarm->wktime.tm_sec == now->tm_sec) + /* wktime stores the next trigger time. Compare the complete time + * of day and only advance the next trigger after a hit, so that a + * reschedule caused by another alarm cannot fire this alarm early + * or corrupt the pending trigger time. */ + if (sec_alarm == sec_now) { + alarm->wktime.tm_hour = now->tm_hour; alarm->wktime.tm_min = now->tm_min + 1; if (alarm->wktime.tm_min > 59) { @@ -168,8 +172,8 @@ static void alarm_wakeup(struct rt_alarm *alarm, struct tm *now) break; case RT_ALARM_HOUR: { - if ((alarm->wktime.tm_min == now->tm_min) && - (alarm->wktime.tm_sec == now->tm_sec)) + /* wktime stores the next trigger time; advance it only on a hit */ + if (sec_alarm == sec_now) { alarm->wktime.tm_hour = now->tm_hour + 1; if (alarm->wktime.tm_hour > 23)