diff options
author | Daniel Gonzalez <daniel.d.gonzalez@intel.com> | 2019-03-27 13:27:05 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-28 11:17:34 -0700 |
commit | b7f764efd2c688970f0ba1252ddc591a092af6dd (patch) | |
tree | 5a48168bc0231c9d9fcd94145dfc8f4cb39cb286 /chip/ish/i2c.c | |
parent | fe2f414d2dcccb6faa30c369eac2c4665b18677a (diff) | |
download | chrome-ec-b7f764efd2c688970f0ba1252ddc591a092af6dd.tar.gz |
ish: I2C transaction to non-existent addresses fix
This patch does not allow for I2C transfers to reserved address
ranges for the I2C module. Also does not allow transactions to
non-existent ports.
Returns an error if writing to a non-reserved, invalid
address range
Reference: DW_apb_i2c.pdf, pg. 74
BUG=b:123357842
BRANCH=none
TEST=i2cxfer commands in ISH console for invalid/valid ports and
addresses on atlas_ish board
Change-Id: Ieeec14b1c9b82e88d8e7658c0c56b10e3735936f
Signed-off-by: Daniel Gonzalez <daniel.d.gonzalez@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1541941
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Li1 Feng <li1.feng@intel.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Kyoung Il Kim <kyoung.il.kim@intel.com>
Diffstat (limited to 'chip/ish/i2c.c')
-rw-r--r-- | chip/ish/i2c.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/chip/ish/i2c.c b/chip/ish/i2c.c index 79f0dd13de..284a46a1cc 100644 --- a/chip/ish/i2c.c +++ b/chip/ish/i2c.c @@ -307,6 +307,16 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, if (out_size == 0 && in_size == 0) return EC_SUCCESS; + if (port < 0 || port >= ISH_I2C_PORT_COUNT) + return EC_ERROR_INVAL; + + /* Check for reserved I2C addresses, pg. 74 in DW_apb_i2c.pdf + * Address cannot be any of the reserved address locations: + * 0x00 to 0x07 or 0x78 to 0x7f. + */ + if (slave_addr <= 0x0F || (slave_addr >= 0xF0 && slave_addr <= 0xFF)) + return EC_ERROR_INVAL; + /* assume that if both out_size and in_size are not zero, * then, it is 'repeated Start' condition. */ if (in_size != 0 && out_size != 0) @@ -408,6 +418,9 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, i2c_mmio_write(ctx->base, IC_ENABLE, IC_ENABLE_DISABLE); + if (ctx->error_flag) + return EC_ERROR_INVAL; + return EC_SUCCESS; } |