summaryrefslogtreecommitdiff
path: root/chip/mchp/i2c.c
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@google.com>2019-08-27 15:51:20 +0200
committerCommit Bot <commit-bot@chromium.org>2019-08-28 08:45:05 +0000
commit0441f941ab17f0c20d97e5d739c88312dd17c6a2 (patch)
treed172fb1c587716172f0e22bb7e149c061bb771ff /chip/mchp/i2c.c
parentd104b49414eccf05c0f78f8317e7bb776e314513 (diff)
downloadchrome-ec-0441f941ab17f0c20d97e5d739c88312dd17c6a2.tar.gz
mchp/i2c: Fix boundary check
It's an off-by-one and the same test is implemented properly in the following function, so use that. (Found by Coverity Scan) BUG=none BRANCH=none TEST=none Change-Id: Idfe3ae0f1128e430a0d52c151e264de86579c67a Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1768649 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Patrick Georgi <pgeorgi@chromium.org> Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
Diffstat (limited to 'chip/mchp/i2c.c')
-rw-r--r--chip/mchp/i2c.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/chip/mchp/i2c.c b/chip/mchp/i2c.c
index 2a43ab4496..c75712bc37 100644
--- a/chip/mchp/i2c.c
+++ b/chip/mchp/i2c.c
@@ -148,9 +148,16 @@ static const uint16_t i2c_controller_pcr[MCHP_I2C_CTRL_MAX] = {
MCHP_PCR_I2C3
};
+static int chip_i2c_is_controller_valid(int controller)
+{
+ if ((controller < 0) || (controller >= MCHP_I2C_CTRL_MAX))
+ return 0;
+ return 1;
+}
+
static void i2c_ctrl_slp_en(int controller, int sleep_en)
{
- if ((controller < 0) || (controller > MCHP_I2C_CTRL_MAX))
+ if (!chip_i2c_is_controller_valid(controller))
return;
if (sleep_en)
MCHP_PCR_SLP_EN_DEV(i2c_controller_pcr[controller]);
@@ -158,13 +165,6 @@ static void i2c_ctrl_slp_en(int controller, int sleep_en)
MCHP_PCR_SLP_DIS_DEV(i2c_controller_pcr[controller]);
}
-static int chip_i2c_is_controller_valid(int controller)
-{
- if ((controller < 0) || (controller >= MCHP_I2C_CTRL_MAX))
- return 0;
- return 1;
-}
-
uint32_t chip_i2c_get_ctx_flags(int port)
{
int controller = i2c_port_to_controller(port);