diff options
author | Dino Li <Dino.Li@ite.com.tw> | 2017-09-13 14:43:59 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-09-13 19:28:30 -0700 |
commit | 3dc53814db8809fe18b21cc2ae89f50d04358ce4 (patch) | |
tree | 9e34ace658ab8b967d12368515a0506d14c8dd30 /common/i2c_master.c | |
parent | af4c8ebcf4cea8b713b9757a5f91219332737a52 (diff) | |
download | chrome-ec-3dc53814db8809fe18b21cc2ae89f50d04358ce4.tar.gz |
i2c: rand of i2ctest console command is unsigned
We use rand to get timestamp counter low word and do random test
(test_dev = rand % i2c_test_dev_used).
But we will get a negative index (test_dev) if low word larger than
0x80000000 and cause the array to access the wrong locations and
trigger an exception.
This change also fix following error:
error: i2c_s_test may be used uninitialized in this function
[-Werror=maybe-uninitialized]
BRANCH=none
BUG=none
TEST="forcetime 0 0x80000000" then "i2ctest", no exception triggered.
Signed-off-by: Dino Li <Dino.Li@ite.com.tw>
Change-Id: Ia2f5a2ff034a6b7b96f7bd4f3b42bf5645a05aed
Reviewed-on: https://chromium-review.googlesource.com/663110
Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common/i2c_master.c')
-rw-r--r-- | common/i2c_master.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/common/i2c_master.c b/common/i2c_master.c index 25b31613fa..b2f9ec285f 100644 --- a/common/i2c_master.c +++ b/common/i2c_master.c @@ -886,13 +886,14 @@ static void i2c_test_status(struct i2c_test_results *i2c_test, int test_dev) static int command_i2ctest(int argc, char **argv) { char *e; - int i, j, rv, rand; + int i, j, rv; + uint32_t rand; int data, data_verify; int port, addr; int count = 10000; int udelay = 100; int test_dev = i2c_test_dev_used; - struct i2c_stress_test_dev *i2c_s_test; + struct i2c_stress_test_dev *i2c_s_test = NULL; struct i2c_test_reg_info *reg_s_info; struct i2c_test_results *test_s_results; |