From 2ffc903ae4c772f2b12897634e24fa8e0c1791ef Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Thu, 24 Jun 2021 17:49:03 +0800 Subject: i2c_controller: add volatile for i2c_port_active_list With the LTO enabled, the i2c_port_active_list might be reordered by linker and causes the i2c lock checking failure. BUG=b:191444593 TEST=i2c waveform looks good, no "Access i2c without lock" complain BRANCH=none Change-Id: I96996c7288b65e74f1734fd14a82f069b6ff11ff Signed-off-by: Eric Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2984257 Tested-by: Eric Yilun Lin Tested-by: Hsu Alvis Reviewed-by: Patrick Georgi Commit-Queue: Eric Yilun Lin --- common/i2c_controller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/i2c_controller.c b/common/i2c_controller.c index 09eb255a22..2e9e1b4b76 100644 --- a/common/i2c_controller.c +++ b/common/i2c_controller.c @@ -50,7 +50,7 @@ static mutex_t port_mutex[I2C_CONTROLLER_COUNT + I2C_BITBANG_PORT_COUNT]; /* A bitmap of the controllers which are currently servicing a request. */ -static uint32_t i2c_port_active_list; +static volatile uint32_t i2c_port_active_list; BUILD_ASSERT(ARRAY_SIZE(port_mutex) < 32); static uint8_t port_protected[I2C_PORT_COUNT + I2C_BITBANG_PORT_COUNT]; @@ -295,7 +295,7 @@ void i2c_lock(int port, int lock) /* Disable interrupt during changing counter for preemption. */ irq_lock_key = irq_lock(); - i2c_port_active_list |= 1 << port; + i2c_port_active_list |= BIT(port); /* EC cannot enter sleep if there's any i2c port active. */ disable_sleep(SLEEP_MASK_I2C_CONTROLLER); -- cgit v1.2.1