diff options
author | Caveh Jalali <caveh@chromium.org> | 2021-09-21 22:56:05 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-26 01:20:49 +0000 |
commit | 8e132f7c5b61466bcca6d7ab7403f44611cbd032 (patch) | |
tree | b69633aca7fe2da2b7c83e2a362a6627b2c8b17d | |
parent | ae0593a3d10e60ea3fe8aa8159458e2dfb290292 (diff) | |
download | chrome-ec-8e132f7c5b61466bcca6d7ab7403f44611cbd032.tar.gz |
common/i2c: Improve port number validation in i2c_set_freq
This adds additional checks to the port number validation in
i2c_set_freq. get_i2c_port could potentially return a NULL pointer, so
check for that. Also, when DYNAMIC_SPEED is not enabled on a port,
return ERROR_UNIMPLEMENTED instead of ERROR_INVAL.
BRANCH=none
BUG=b:201039003
TEST=with follow-on patches, switched I2C bus speed between 400 kHz
and 1 MHz.
Change-Id: Ie58d68ee2b64d94681ea1d5044530195210ff661
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3181503
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Boris Mittelberg <bmbm@google.com>
-rw-r--r-- | common/i2c_controller.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/common/i2c_controller.c b/common/i2c_controller.c index fabb0e34f3..9fd68aaa2d 100644 --- a/common/i2c_controller.c +++ b/common/i2c_controller.c @@ -1113,10 +1113,15 @@ unwedge_done: int i2c_set_freq(int port, enum i2c_freq freq) { int ret; + const struct i2c_port_t *cfg; - if (!(get_i2c_port(port)->flags & I2C_PORT_FLAG_DYNAMIC_SPEED)) + cfg = get_i2c_port(port); + if (cfg == NULL) return EC_ERROR_INVAL; + if (!(cfg->flags & I2C_PORT_FLAG_DYNAMIC_SPEED)) + return EC_ERROR_UNIMPLEMENTED; + i2c_lock(port, 1); ret = chip_i2c_set_freq(port, freq); i2c_lock(port, 0); |