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>
This commit is contained in:
Dino Li
2017-09-13 14:43:59 +08:00
committed by chrome-bot
parent af4c8ebcf4
commit 3dc53814db

View File

@@ -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;