diff options
author | Edward Hill <ecgh@chromium.org> | 2020-08-14 15:33:09 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-15 01:47:31 +0000 |
commit | 55554e281b65e4ca780bc1dfee28c2599e781efc (patch) | |
tree | a11b86da0b53206af0a6e98e3adffc340a764929 | |
parent | 29ad5a3e08fef053ffe8d56d004d868a8794481a (diff) | |
download | chrome-ec-55554e281b65e4ca780bc1dfee28c2599e781efc.tar.gz |
task: Change mutex_lock() assert
Instead of asserting that task_start() has not been called,
just return without doing any locking.
This avoids the need to fix every caller of mutex_lock() to check
task_start_called().
BUG=b:164461158
BRANCH=none
TEST=Esc+F3+Power enters recovery, does not assert.
Signed-off-by: Edward Hill <ecgh@chromium.org>
Change-Id: Ic157d7e7041185a67f257f0f5710fd02e45cd77f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2357496
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Commit-Queue: Wai-Hong Tam <waihong@google.com>
-rw-r--r-- | chip/npcx/flash.c | 4 | ||||
-rw-r--r-- | chip/stm32/bkpdata.c | 10 | ||||
-rw-r--r-- | common/i2c_master.c | 4 | ||||
-rw-r--r-- | core/cortex-m/task.c | 17 | ||||
-rw-r--r-- | power/common.c | 9 |
5 files changed, 18 insertions, 26 deletions
diff --git a/chip/npcx/flash.c b/chip/npcx/flash.c index b2b51d15df..7afb413c2c 100644 --- a/chip/npcx/flash.c +++ b/chip/npcx/flash.c @@ -726,10 +726,6 @@ int flash_pre_init(void) void flash_lock_mapped_storage(int lock) { - /* Must not call mutex_lock() before task_start(). */ - if (!task_start_called()) - return; - if (lock) mutex_lock(&flash_lock); else diff --git a/chip/stm32/bkpdata.c b/chip/stm32/bkpdata.c index c31c1a9185..2b26ace7ea 100644 --- a/chip/stm32/bkpdata.c +++ b/chip/stm32/bkpdata.c @@ -23,7 +23,6 @@ uint16_t bkpdata_read(enum bkpdata_index index) int bkpdata_write(enum bkpdata_index index, uint16_t value) { - int use_mutex = task_start_called(); static struct mutex bkpdata_write_mutex; if (index < 0 || index >= STM32_BKP_ENTRIES) @@ -31,11 +30,9 @@ int bkpdata_write(enum bkpdata_index index, uint16_t value) /* * Two entries share a single 32-bit register, lock mutex to prevent - * read/mask/write races. Must not call mutex_lock() before - * task_start(). + * read/mask/write races. */ - if (use_mutex) - mutex_lock(&bkpdata_write_mutex); + mutex_lock(&bkpdata_write_mutex); if (index & 1) { uint32_t val = STM32_BKP_DATA(index >> 1); val = (val & 0x0000FFFF) | (value << 16); @@ -45,8 +42,7 @@ int bkpdata_write(enum bkpdata_index index, uint16_t value) val = (val & 0xFFFF0000) | value; STM32_BKP_DATA(index >> 1) = val; } - if (use_mutex) - mutex_unlock(&bkpdata_write_mutex); + mutex_unlock(&bkpdata_write_mutex); return EC_SUCCESS; } diff --git a/common/i2c_master.c b/common/i2c_master.c index 78a5e505b9..f078e690f7 100644 --- a/common/i2c_master.c +++ b/common/i2c_master.c @@ -242,10 +242,6 @@ void i2c_prepare_sysjump(void) { int i; - /* Must not call mutex_lock() before task_start(). */ - if (!task_start_called()) - return; - /* Lock all i2c controllers */ for (i = 0; i < ARRAY_SIZE(port_mutex); ++i) mutex_lock(port_mutex + i); diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index 61697d2684..d64f9400b6 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -858,14 +858,23 @@ static void __nvic_init_irqs(void) void mutex_lock(struct mutex *mtx) { uint32_t value; - uint32_t id = 1 << task_get_current(); + uint32_t id; /* * mutex_lock() must not be used in interrupt context (because we wait - * if there is contention). Task ID is not valid before task_start() - * (since current_task is scratchpad). + * if there is contention). */ - ASSERT(!in_interrupt_context() && task_start_called()); + ASSERT(!in_interrupt_context()); + + /* + * 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; + + id = 1 << task_get_current(); atomic_or(&mtx->waiters, id); diff --git a/power/common.c b/power/common.c index b3200fd186..0cdabca0fa 100644 --- a/power/common.c +++ b/power/common.c @@ -1049,15 +1049,10 @@ DECLARE_HOOK(HOOK_INIT, restore_enable_5v_state, HOOK_PRIO_FIRST); static void preserve_enable_5v_state(void) { - /* Must not call mutex_lock() before task_start(). */ - int use_mutex = task_start_called(); - - if (use_mutex) - mutex_lock(&pwr_5v_ctl_mtx); + mutex_lock(&pwr_5v_ctl_mtx); system_add_jump_tag(P5_SYSJUMP_TAG, 0, sizeof(pwr_5v_en_req), &pwr_5v_en_req); - if (use_mutex) - mutex_unlock(&pwr_5v_ctl_mtx); + mutex_unlock(&pwr_5v_ctl_mtx); } DECLARE_HOOK(HOOK_SYSJUMP, preserve_enable_5v_state, HOOK_PRIO_DEFAULT); #endif /* defined(CONFIG_POWER_PP5000_CONTROL) */ |