summaryrefslogtreecommitdiff
path: root/core/cortex-m
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2020-07-18 19:08:06 -0600
committerCommit Bot <commit-bot@chromium.org>2020-07-24 00:29:43 +0000
commitd53b71c17f7845a591fe4099b53717ec28bf5ccf (patch)
treea3a4239fb9f964daa14f8d0cf64d0e7a294c3c0c /core/cortex-m
parentccc0145eeb4530c53a84807ca2ae4691a8534130 (diff)
downloadchrome-ec-d53b71c17f7845a591fe4099b53717ec28bf5ccf.tar.gz
task: Fix mutex_lock() assert
mutex_lock() must not be used in interrupt context. Add an assert to catch this. Also add a check for task_start_called() since task ID is not valid before this. Also remove an old assert since comparing id with TASK_ID_INVALID doesn't make sense. BUG=b:160975910 BRANCH=none TEST=boot AP Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I1a941fa78849a4efe586e66bb4787aa5a2a67732 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2309057 Reviewed-by: Raul E Rangel <rrangel@chromium.org>
Diffstat (limited to 'core/cortex-m')
-rw-r--r--core/cortex-m/task.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index 75fbf99155..4dde20aa9a 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -860,7 +860,20 @@ void mutex_lock(struct mutex *mtx)
uint32_t value;
uint32_t id = 1 << task_get_current();
- ASSERT(id != TASK_ID_INVALID);
+ /*
+ * Task ID is not valid before task_start() (since current_task is
+ * scratchpad), and no need for mutex locking before task switching has
+ * begun.
+ */
+ if (!task_start_called())
+ return;
+
+ /*
+ * mutex_lock() must not be used in interrupt context (because we wait
+ * if there is contention).
+ */
+ ASSERT(!in_interrupt_context());
+
atomic_or(&mtx->waiters, id);
do {