From 3dc53814db8809fe18b21cc2ae89f50d04358ce4 Mon Sep 17 00:00:00 2001 From: Dino Li Date: Wed, 13 Sep 2017 14:43:59 +0800 Subject: 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 Change-Id: Ia2f5a2ff034a6b7b96f7bd4f3b42bf5645a05aed Reviewed-on: https://chromium-review.googlesource.com/663110 Reviewed-by: Vijay P Hiremath Reviewed-by: Shawn N --- common/i2c_master.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'common/i2c_master.c') 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; -- cgit v1.2.1