summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-31 18:26:55 -0700
committerVic Yang <victoryang@chromium.org>2012-10-31 19:21:46 -0700
commit97b1886600cb9510e9ca2ea1c644e831fd4540c4 (patch)
tree272177da532843a21c60a259a0d49a67df341550
parentf55e55322834db625bfffe02371e9f258412a024 (diff)
downloadchrome-ec-97b1886600cb9510e9ca2ea1c644e831fd4540c4.tar.gz
link: Fix overflow in hibernate time calculation
The time out value passed to task_wait_event() is signed 32-bit and thus waiting for 24 hours will cause overflow. Limit max wait time. BUG=chrome-os-partner:15797 BRANCH=link TEST=Disconnect AC, shut down system, and close lid. From ec console, do 'hibdelay 8000' and then wait 2.5 hours. EC should have hibernated. (8000 is more than twice the max time for task_wait_event()) Change-Id: I8f368262edfe6bf90046705b864fc52fb3503d02 Original-Change-Id: I5fa505554182e8bad6399c12a382ff71bb123d8f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/37096 Reviewed-by: Vic Yang <victoryang@chromium.org>
-rw-r--r--common/x86_power.c6
-rw-r--r--include/task.h3
2 files changed, 8 insertions, 1 deletions
diff --git a/common/x86_power.c b/common/x86_power.c
index 567af54f77..16a3e0d258 100644
--- a/common/x86_power.c
+++ b/common/x86_power.c
@@ -450,8 +450,12 @@ void x86_power_task(void)
system_hibernate(0, 0);
}
else {
+ uint64_t wait = target_time - time_now;
+ if (wait > TASK_MAX_WAIT_US)
+ wait = TASK_MAX_WAIT_US;
+
/* Wait for a message */
- task_wait_event(target_time - time_now);
+ task_wait_event(wait);
}
}
diff --git a/include/task.h b/include/task.h
index c6b8b4591d..92ef9adc29 100644
--- a/include/task.h
+++ b/include/task.h
@@ -21,6 +21,9 @@
* task_wait_event() timed out before
* receiving another event. */
+/* Maximum time for task_wait_event() */
+#define TASK_MAX_WAIT_US 0x7fffffff
+
/* Disable CPU interrupt bit. This might break the system so think really hard
* before using these. There are usually better ways of accomplishing this. */
void interrupt_disable(void);