From: "Frank Schäfer" <fschaefer.oss@googlemail.com>
To: mchehab@redhat.com
Cc: linux-media@vger.kernel.org,
"Frank Schäfer" <fschaefer.oss@googlemail.com>
Subject: [PATCH v2 2/5] em28xx: respect the message size constraints for i2c transfers
Date: Sun, 16 Dec 2012 19:23:28 +0100 [thread overview]
Message-ID: <1355682211-13604-3-git-send-email-fschaefer.oss@googlemail.com> (raw)
In-Reply-To: <1355682211-13604-1-git-send-email-fschaefer.oss@googlemail.com>
The em2800 can transfer up to 4 bytes per i2c message.
All other em25xx/em27xx/28xx chips can transfer at least 64 bytes per message.
I2C adapters should never split messages transferred via the I2C subsystem
into multiple message transfers, because the result will almost always NOT be
the same as when the whole data is transferred to the I2C client in a single
message.
If the message size exceeds the capabilities of the I2C adapter, -EOPNOTSUPP
should be returned.
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
drivers/media/usb/em28xx/em28xx-i2c.c | 44 ++++++++++++++-------------------
1 Datei geändert, 18 Zeilen hinzugefügt(+), 26 Zeilen entfernt(-)
diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c
index 44533e4..c508c12 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -50,14 +50,18 @@ do { \
} while (0)
/*
- * em2800_i2c_send_max4()
- * send up to 4 bytes to the i2c device
+ * em2800_i2c_send_bytes()
+ * send up to 4 bytes to the em2800 i2c device
*/
-static int em2800_i2c_send_max4(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
+static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
{
int ret;
int write_timeout;
u8 b2[6];
+
+ if (len < 1 || len > 4)
+ return -EOPNOTSUPP;
+
BUG_ON(len < 1 || len > 4);
b2[5] = 0x80 + len - 1;
b2[4] = addr;
@@ -86,29 +90,6 @@ static int em2800_i2c_send_max4(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
}
/*
- * em2800_i2c_send_bytes()
- */
-static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
-{
- u8 *bufPtr = buf;
- int ret;
- int wrcount = 0;
- int count;
- int maxLen = 4;
- while (len > 0) {
- count = (len > maxLen) ? maxLen : len;
- ret = em2800_i2c_send_max4(dev, addr, bufPtr, count);
- if (ret > 0) {
- len -= count;
- bufPtr += count;
- wrcount += count;
- } else
- return (ret < 0) ? ret : -EFAULT;
- }
- return wrcount;
-}
-
-/*
* em2800_i2c_check_for_device()
* check if there is a i2c_device at the supplied address
*/
@@ -150,6 +131,10 @@ static int em2800_i2c_check_for_device(struct em28xx *dev, u8 addr)
static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
{
int ret;
+
+ if (len < 1 || len > 4)
+ return -EOPNOTSUPP;
+
/* check for the device and set i2c read address */
ret = em2800_i2c_check_for_device(dev, addr);
if (ret) {
@@ -176,6 +161,9 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
int wrcount = 0;
int write_timeout, ret;
+ if (len < 1 || len > 64)
+ return -EOPNOTSUPP;
+
wrcount = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
/* Seems to be required after a write */
@@ -197,6 +185,10 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len)
{
int ret;
+
+ if (len < 1 || len > 64)
+ return -EOPNOTSUPP;
+
ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len);
if (ret < 0) {
em28xx_warn("reading i2c device failed (error=%i)\n", ret);
--
1.7.10.4
next prev parent reply other threads:[~2012-12-16 18:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-16 18:23 [PATCH v2 0/5] em28xx: i2c bug fixes and cleanups Frank Schäfer
2012-12-16 18:23 ` [PATCH v2 1/5] em28xx: clean up the data type mess of the i2c transfer function parameters Frank Schäfer
2012-12-16 18:23 ` Frank Schäfer [this message]
2012-12-23 0:07 ` [PATCH v2 2/5] em28xx: respect the message size constraints for i2c transfers Mauro Carvalho Chehab
2012-12-23 13:58 ` Frank Schäfer
2012-12-23 14:46 ` Mauro Carvalho Chehab
2012-12-24 11:09 ` Frank Schäfer
2013-01-02 19:29 ` Antti Palosaari
2013-01-02 21:12 ` Frank Schäfer
2013-01-02 21:15 ` Antti Palosaari
2013-01-02 21:29 ` Frank Schäfer
2013-01-02 21:40 ` Antti Palosaari
2013-01-02 21:52 ` Frank Schäfer
2013-01-02 20:45 ` Sascha Sommer
2013-01-02 21:25 ` Frank Schäfer
2013-01-02 22:21 ` Sascha Sommer
2013-01-03 17:49 ` Frank Schäfer
2012-12-16 18:23 ` [PATCH v2 3/5] em28xx: fix two severe bugs in function em2800_i2c_recv_bytes() Frank Schäfer
2012-12-16 18:23 ` [PATCH v2 4/5] em28xx: fix the i2c adapter functionality flags Frank Schäfer
2012-12-16 18:23 ` [PATCH v2 5/5] em28xx: fix+improve+unify i2c error handling, debug messages and code comments Frank Schäfer
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=1355682211-13604-3-git-send-email-fschaefer.oss@googlemail.com \
--to=fschaefer.oss@googlemail.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).