diff options
author | Martin Roth <martinroth@chromium.org> | 2016-08-12 12:27:55 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-12-16 15:42:47 -0800 |
commit | fd355c219f46ef0b55d6e1abea6b94f148ac1280 (patch) | |
tree | a0de09c9b0a8cbc7920f25aa29bac35ab1e9b216 /common | |
parent | e2409e3921d657f8c57fd6105d17ae0b7ad62e6b (diff) | |
download | chrome-ec-fd355c219f46ef0b55d6e1abea6b94f148ac1280.tar.gz |
common/i2c.c: Check that i2c port is always 0 or greater
Previously, an assert was checking the port value after the
port value had been converted to the controller. Instead, verify
that the value is not negative, and return if it is.
The if sequence generates much less code than the ASSERT, and protects
both paths.
Fixes coverity warning 141748: Negative array index read
42 files changed.
Total size change: -1248 bytes.
Average size change: -29 bytes.
These platforms increased in size:
lucid/RO/ec.RO.flat grew by 4 bytes: (64404 to 64408)
lucid/RW/ec.RW.flat grew by 20 bytes: (63996 to 64016)
pyro/RO/ec.RO.flat grew by 120 bytes: (131212 to 131332)
pyro/RW/ec.RW.flat grew by 144 bytes: (130764 to 130908)
TEST=Build
BUG=None
BRANCH=None
Change-Id: I8d39db04c4ca3194f99e17840365429ed2d39390
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/371401
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/i2c.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/common/i2c.c b/common/i2c.c index df5bb44b37..8255484b3c 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -70,8 +70,10 @@ void i2c_lock(int port, int lock) #ifdef CONFIG_I2C_MULTI_PORT_CONTROLLER /* Lock the controller, not the port */ port = i2c_port_to_controller(port); - ASSERT(port != -1); #endif + if (port < 0) + return; + if (lock) { mutex_lock(port_mutex + port); |