summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Hajec <lha@semihalf.com>2021-08-23 18:25:39 +0200
committerCommit Bot <commit-bot@chromium.org>2021-08-26 21:07:19 +0000
commit7c76fa1283ae59fd971d0f46c1bb15291b4c610c (patch)
tree7e1a42f9673e499ae0d6e6825d2c062eb23010c4
parent703b208c9eb4880aeb47ba21da3203ea5d4f78d8 (diff)
downloadchrome-ec-7c76fa1283ae59fd971d0f46c1bb15291b4c610c.tar.gz
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 <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> (cherry picked from commit faa5ff511aa464f5fee621eef7b8bf4cdeb26ad5) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3113967 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--common/i2c_master.c3
1 files changed, 3 insertions, 0 deletions
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);