summaryrefslogtreecommitdiff
path: root/chip/stm32
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2020-07-18 19:08:06 -0600
committerCommit Bot <commit-bot@chromium.org>2020-08-12 03:13:01 +0000
commite6956209119d2b2c1f45401855019e3a0a2f7dd5 (patch)
treedfe7c3b1e31cc449348a7627c4a7890aeca5154a /chip/stm32
parentdbcab40b7b8696d56b4708f37f84883ae3e0c8bf (diff)
downloadchrome-ec-e6956209119d2b2c1f45401855019e3a0a2f7dd5.tar.gz
task: Fix mutex_lock() assert (reland)
mutex_lock() must not be used in interrupt context. Add an assert to catch this. Also assert 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. Add check for task_start_called() for NPCX flash_lock, I2C port_mutex, pwr_5v_ctl_mtx, STM32 bkpdata_write_mutex. This was submitted CL:2309057, reverted CL:2323704, submitted CL:2335738, reverted CL:2341706. BUG=b:160975910 BRANCH=none TEST=boot AP, jump to RW Signed-off-by: Edward Hill <ecgh@chromium.org> Change-Id: I0aadf29d073f0d3d798432099bd024a058332412 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2343450 Reviewed-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r--chip/stm32/bkpdata.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/chip/stm32/bkpdata.c b/chip/stm32/bkpdata.c
index 2b26ace7ea..c31c1a9185 100644
--- a/chip/stm32/bkpdata.c
+++ b/chip/stm32/bkpdata.c
@@ -23,6 +23,7 @@ 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)
@@ -30,9 +31,11 @@ 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.
+ * read/mask/write races. Must not call mutex_lock() before
+ * task_start().
*/
- mutex_lock(&bkpdata_write_mutex);
+ if (use_mutex)
+ mutex_lock(&bkpdata_write_mutex);
if (index & 1) {
uint32_t val = STM32_BKP_DATA(index >> 1);
val = (val & 0x0000FFFF) | (value << 16);
@@ -42,7 +45,8 @@ int bkpdata_write(enum bkpdata_index index, uint16_t value)
val = (val & 0xFFFF0000) | value;
STM32_BKP_DATA(index >> 1) = val;
}
- mutex_unlock(&bkpdata_write_mutex);
+ if (use_mutex)
+ mutex_unlock(&bkpdata_write_mutex);
return EC_SUCCESS;
}