From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 6/7] i2c: mv_i2c.c: Validate read length in I2C command
Date: Fri, 16 Sep 2016 15:07:54 +0200 [thread overview]
Message-ID: <20160916130755.9883-6-sr@denx.de> (raw)
In-Reply-To: <20160916130755.9883-1-sr@denx.de>
From: jinghua <jinghua@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@marvell.com>
Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Nadav Haklai <nadavh@marvell.com>
Cc: Kostya Porotchkin <kostap@marvell.com>
Cc: Wilson Ding <dingwei@marvell.com>
Cc: Victor Gu <xigu@marvell.com>
Cc: Hua Jing <jinghua@marvell.com>
Cc: Terry Zhou <bjzhou@marvell.com>
Cc: Hanna Hawa <hannah@marvell.com>
Cc: Haim Boot <hayim@marvell.com>
Cc: Heiko Schocher <hs@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
next prev parent reply other threads:[~2016-09-16 13:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-16 13:07 [U-Boot] [PATCH 1/7] i2c: mv_i2c.c: cosmetic: Coding style cleanups Stefan Roese
2016-09-16 13:07 ` [U-Boot] [PATCH 2/7] i2c: mv_i2c.c: Remove CONFIG_HARD_I2C Stefan Roese
2016-09-16 13:07 ` [U-Boot] [PATCH 3/7] i2c: mv_i2c.c: Prepare driver for DM conversion Stefan Roese
2016-09-16 13:07 ` [U-Boot] [PATCH 4/7] i2c: mv_i2c.c: Add DM support Stefan Roese
2016-09-16 13:07 ` [U-Boot] [PATCH 5/7] i2c: mv_i2c.c: Enable runtime speed selection (standard vs fast mode) Stefan Roese
2016-09-16 13:07 ` Stefan Roese [this message]
2016-09-16 13:07 ` [U-Boot] [PATCH 7/7] i2c: mvtwsi.c: Add support for Marvell Armada 7K/8K Stefan Roese
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160916130755.9883-6-sr@denx.de \
--to=sr@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox