summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/npcx/flash.c4
-rw-r--r--chip/stm32/bkpdata.c10
-rw-r--r--common/i2c_master.c4
-rw-r--r--core/cortex-m/task.c17
-rw-r--r--power/common.c9
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) */