diff options
author | Philip Chen <philipchen@google.com> | 2017-12-04 16:56:23 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-12-06 17:30:47 -0800 |
commit | e2a9ede352111e0943377a275accf4a13c71d777 (patch) | |
tree | 2b83ab35513360386656e9859b491ffce88b8e39 /chip/stm32 | |
parent | bedf1f5a614ef324e111f761c8c9693e2b8c2812 (diff) | |
download | chrome-ec-e2a9ede352111e0943377a275accf4a13c71d777.tar.gz |
chip/stm32/clock: Handle illegal alarm timeout gracefully
Even if we set the rtc alarm timeout for more than 86400 secs,
we should not crash the system.
BUG=chromium:768042
BRANCH=none
TEST=on AP console, do 'ectool rtcsetalarm 99999' and
then see 'EC result 3 (INVALID_PARAM)' without crash.
Change-Id: Ic0fa92ff101bce1f4791221c4e1eadaf7a005355
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/807624
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r-- | chip/stm32/clock-f.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/chip/stm32/clock-f.c b/chip/stm32/clock-f.c index 025eaf0246..e3fcc02a1d 100644 --- a/chip/stm32/clock-f.c +++ b/chip/stm32/clock-f.c @@ -172,8 +172,7 @@ void set_rtc_alarm(uint32_t delay_s, uint32_t delay_us, return; } - /* Alarm must be within 1 day (86400 seconds) */ - + /* Alarm timeout must be within 1 day (86400 seconds) */ ASSERT((delay_s + delay_us / SECOND) < SECS_PER_DAY); rtc_unlock_regs(); @@ -195,8 +194,8 @@ void set_rtc_alarm(uint32_t delay_s, uint32_t delay_us, * If seconds is greater than 1 day, subtract by 1 day to deal with * 24-hour rollover. */ - if (alarm_sec >= 86400) - alarm_sec -= 86400; + if (alarm_sec >= SECS_PER_DAY) + alarm_sec -= SECS_PER_DAY; /* Set alarm time */ STM32_RTC_ALRMAR = sec_to_rtc_tr(alarm_sec); @@ -406,8 +405,13 @@ static int system_rtc_set_alarm(struct host_cmd_handler_args *args) struct rtc_time_reg rtc; const struct ec_params_rtc *p = args->params; + /* Alarm timeout must be within 1 day (86400 seconds) */ + if (p->time >= SECS_PER_DAY) + return EC_RES_INVALID_PARAM; + if (p->time != EC_RTC_ALARM_CLEAR) host_rtc_alarm_set = 1; + set_rtc_alarm(p->time, 0, &rtc); return EC_RES_SUCCESS; } |