[U-Boot] [PATCH 6/7] i2c: mv_i2c.c: Validate read length in I2C command

Stefan Roese sr at denx.de
Fri Sep 16 15:07:54 CEST 2016


From: jinghua <jinghua at marvell.com>

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 <jinghua at marvell.com>
Signed-off-by: Stefan Roese <sr at denx.de>
Cc: Nadav Haklai <nadavh at marvell.com>
Cc: Kostya Porotchkin <kostap at marvell.com>
Cc: Wilson Ding <dingwei at marvell.com>
Cc: Victor Gu <xigu at marvell.com>
Cc: Hua Jing <jinghua at marvell.com>
Cc: Terry Zhou <bjzhou at marvell.com>
Cc: Hanna Hawa <hannah at marvell.com>
Cc: Haim Boot <hayim at marvell.com>
Cc: Heiko Schocher <hs at denx.de>
---
 drivers/i2c/mv_i2c.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/mv_i2c.c b/drivers/i2c/mv_i2c.c
index 291b2d7..7f52fa2 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 */
-- 
2.9.3



More information about the U-Boot mailing list