summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorLukasz Hajec <lha@semihalf.com>2021-07-21 14:12:51 +0200
committerCommit Bot <commit-bot@chromium.org>2021-08-06 12:42:48 +0000
commitfaa5ff511aa464f5fee621eef7b8bf4cdeb26ad5 (patch)
tree04e9f158e5613e6ea436c5371ed1c49f5c755cd9 /common
parentf5dae73f4f7a8d1667fef490ddcd3114b01a61da (diff)
downloadchrome-ec-faa5ff511aa464f5fee621eef7b8bf4cdeb26ad5.tar.gz
i2c_controller: Check if get_i2c_port returns NULL
This patch fixes an issue, when nonexistent port number parameter is passed to i2cxfer and causes panic due to using null pointer. Add check if get_i2c_port returns NULL and return EC_ERROR_INVAL. BUG=b:186873536 BRANCH=none TEST=Run i2cxfer command with different parameters on servo_v4p1, nocturne and grunt - do not observe panic. Signed-off-by: Lukasz Hajec <lha@semihalf.com> Change-Id: I8bd90d898e1097b59ca6c9a1eff850bc2dc808e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3074620 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/i2c_controller.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/common/i2c_controller.c b/common/i2c_controller.c
index 0596ddc422..90aed056ae 100644
--- a/common/i2c_controller.c
+++ b/common/i2c_controller.c
@@ -125,6 +125,9 @@ __maybe_unused static int chip_i2c_xfer_with_notify(
uint16_t no_pec_af = addr_flags;
const struct i2c_port_t *i2c_port = get_i2c_port(port);
+ if (i2c_port == NULL)
+ return EC_ERROR_INVAL;
+
if (IS_ENABLED(CONFIG_I2C_XFER_BOARD_CALLBACK))
i2c_start_xfer_notify(port, addr_flags);