From: jinghua Date: Fri, 16 Sep 2016 13:07:54 +0000 (+0200) Subject: i2c: mv_i2c.c: Validate read length in I2C command X-Git-Tag: v2016.11-rc1~44 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=85f03f0ea8532498d0fbae0749c23ee85e181322;p=u-boot i2c: mv_i2c.c: Validate read length in I2C command The I2C bus will get stuck when reading 0 byte. So we add validation of the read length in i2c_read(). This issue only occurs on read operation. Signed-off-by: jinghua Signed-off-by: Stefan Roese Cc: Nadav Haklai Cc: Kostya Porotchkin Cc: Wilson Ding Cc: Victor Gu Cc: Hua Jing Cc: Terry Zhou Cc: Hanna Hawa Cc: Haim Boot Cc: Heiko Schocher --- diff --git a/drivers/i2c/mv_i2c.c b/drivers/i2c/mv_i2c.c index 291b2d7e68..7f52fa2d85 100644 --- a/drivers/i2c/mv_i2c.c +++ b/drivers/i2c/mv_i2c.c @@ -243,6 +243,11 @@ static int __i2c_read(struct mv_i2c *base, uchar chip, u8 *addr, int alen, debug("i2c_read(chip=0x%02x, addr=0x%02x, alen=0x%02x, " "len=0x%02x)\n", chip, *addr, alen, len); + if (len == 0) { + printf("reading zero byte is invalid\n"); + return -EINVAL; + } + i2c_reset(base); /* dummy chip address write */