diff options
author | ChromeOS Developer <dparker@chromium.org> | 2014-01-15 22:14:43 -0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-01-28 02:43:55 +0000 |
commit | aa636df6ab83d8ca08dc87c4140dceb40dd65900 (patch) | |
tree | 2ea79b927f0ec826f7552beaafbd4eac4b6254e3 | |
parent | 7263e4571d77d347ed8bd3ce261adddcc4c52c39 (diff) | |
download | chrome-ec-aa636df6ab83d8ca08dc87c4140dceb40dd65900.tar.gz |
Check for valid i2c port number on i2c host commands
BUG=chrome-os-partner:25052
BRANCH=baytrail
TEST=Run ectool i2cread, i2cwrite, and i2cxfer commands
with invalid port numbers. Verify machine doesn't reboot.
Change-Id: Ifef062cb4a7548278f69689072324704f2f66317
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/182911
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/i2c.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/common/i2c.c b/common/i2c.c index 564a4e39a7..995d7cb7cb 100644 --- a/common/i2c.c +++ b/common/i2c.c @@ -119,6 +119,16 @@ int i2c_write8(int port, int slave_addr, int offset, int data) * as ectool supports EC_CMD_I2C_PASSTHRU. */ +static int port_is_valid(int port) +{ + int i; + + for (i = 0; i < i2c_ports_used; i++) + if (i2c_ports[i].port == port) + return 1; + return 0; +} + static int i2c_command_read(struct host_cmd_handler_args *args) { const struct ec_params_i2c_read *p = args->params; @@ -130,7 +140,10 @@ static int i2c_command_read(struct host_cmd_handler_args *args) return EC_RES_ACCESS_DENIED; #endif - if (p->read_size == 16) + if (!port_is_valid(p->port)) + return EC_RES_INVALID_PARAM; + + if (p->read_size == 16) rv = i2c_read16(p->port, p->addr, p->offset, &data); else if (p->read_size == 8) rv = i2c_read8(p->port, p->addr, p->offset, &data); @@ -154,6 +167,9 @@ static int i2c_command_write(struct host_cmd_handler_args *args) return EC_RES_ACCESS_DENIED; #endif + if (!port_is_valid(p->port)) + return EC_RES_INVALID_PARAM; + if (p->write_size == 16) rv = i2c_write16(p->port, p->addr, p->offset, p->data); else if (p->write_size == 8) @@ -200,7 +216,7 @@ static int check_i2c_params(const struct host_cmd_handler_args *args) return EC_RES_INVALID_PARAM; } - if (params->port >= I2C_PORT_COUNT) { + if (!port_is_valid(params->port)) { PTHRUPRINTF("[%T i2c passthru invalid port %d]\n", params->port); return EC_RES_INVALID_PARAM; |