summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2020-10-08 10:28:17 -0700
committerCommit Bot <commit-bot@chromium.org>2020-10-09 23:34:52 +0000
commit19260e58511d3a2e6953be36930b410f129a33dc (patch)
treec9f62f143d3f0e2258524895bda3d62cd32b8b36
parent4afe356a38c7599e83ac637caa385728ce397a0b (diff)
downloadchrome-ec-19260e58511d3a2e6953be36930b410f129a33dc.tar.gz
chip/stm32: Only use a mutex when not in interrupt context
Mutexes shouldn't be used in interrupt context. An ASSERT was added in mutex_lock to verify this commit e6956209119d2b2c1f45401855019e3a0a2f7dd5. There are cases where bkpdata_write can be called from an interrupt context, such as this stack trace that occurs when adding entropy from RO on dartmonkey/icetower (stack captured with Segger J-Trace): > rollbackaddent 1234 panic_assert_fail panic_output.c:132 mutex_lock task.c:889 bkpdata_write bkpdata.c:35 bkpdata_write bkpdata.c:24 bkpdata_write_reset_flags bkpdata.c:86 chip_save_reset_flags system.c:366 system_reset system.c:366 panic_reboot panic_output.c:114 report_panic panic.c:339 exception_panic panic.c:350 Validation of the fix was checked with the "rollback_region1" unit test, which failed before the change and works after. BRANCH=none BUG=b:170147314 TEST=./test/run_device_tests.py -b dartmonkey -t rollback_region1 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ie5509ec024e94b48c786199ccbb81ce93fafe547 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2462545 Reviewed-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--chip/stm32/bkpdata.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/chip/stm32/bkpdata.c b/chip/stm32/bkpdata.c
index 2b26ace7ea..bb1a7a5de3 100644
--- a/chip/stm32/bkpdata.c
+++ b/chip/stm32/bkpdata.c
@@ -24,6 +24,7 @@ uint16_t bkpdata_read(enum bkpdata_index index)
int bkpdata_write(enum bkpdata_index index, uint16_t value)
{
static struct mutex bkpdata_write_mutex;
+ int use_mutex = !in_interrupt_context();
if (index < 0 || index >= STM32_BKP_ENTRIES)
return EC_ERROR_INVAL;
@@ -32,7 +33,8 @@ 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.
*/
- 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 +44,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;
}