From 7c76fa1283ae59fd971d0f46c1bb15291b4c610c Mon Sep 17 00:00:00 2001 From: Lukasz Hajec Date: Mon, 23 Aug 2021 18:25:39 +0200 Subject: i2c_master: 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_v4, nocturne and grunt - do not observe panic. Signed-off-by: Lukasz Hajec Change-Id: I8bd90d898e1097b59ca6c9a1eff850bc2dc808e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3074620 Reviewed-by: Daisuke Nojiri Reviewed-by: Ruben Rodriguez Buchillon (cherry picked from commit faa5ff511aa464f5fee621eef7b8bf4cdeb26ad5) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3113967 Commit-Queue: Daisuke Nojiri --- common/i2c_master.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/i2c_master.c b/common/i2c_master.c index 17c46fc68c..e4b328de52 100644 --- a/common/i2c_master.c +++ b/common/i2c_master.c @@ -98,6 +98,9 @@ static int chip_i2c_xfer_with_notify(const int port, uint16_t addr_flags = slave_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_DEBUG)) i2c_trace_notify(port, slave_addr_flags, 0, out, out_size); -- cgit v1.2.1