* [PATCH v3] HID: cp2112: support large i2c transfers in hid-cp2112
@ 2015-07-08 18:17 Ellen Wang
2015-07-09 12:17 ` Jiri Kosina
0 siblings, 1 reply; 3+ messages in thread
From: Ellen Wang @ 2015-07-08 18:17 UTC (permalink / raw)
To: borneo.antonio, dbarksdale, jkosina, linux-input, linux-i2c; +Cc: ellen
cp2112_i2c_xfer() only reads up to 61 bytes, returning EIO
on longers reads. The fix is to wrap a loop around
cp2112_read() to pick up all the returned data.
Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
---
This is the updated patch with a check for 0 return from
cp2112_read(). I tested it with a suitable delay in the loop
to trigger the cp2112_raw_event() overrun bug, which must
be fixed before this patch is applied.
---
drivers/hid/hid-cp2112.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 3318de6..80e3488 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -509,13 +509,30 @@ static int cp2112_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
if (!(msgs->flags & I2C_M_RD))
goto finish;
- ret = cp2112_read(dev, msgs->buf, msgs->len);
- if (ret < 0)
- goto power_normal;
- if (ret != msgs->len) {
- hid_warn(hdev, "short read: %d < %d\n", ret, msgs->len);
- ret = -EIO;
- goto power_normal;
+ for (count = 0; count < msgs->len;) {
+ ret = cp2112_read(dev, msgs->buf + count, msgs->len - count);
+ if (ret < 0)
+ goto power_normal;
+ if (ret == 0) {
+ hid_err(hdev, "read returned 0\n");
+ ret = -EIO;
+ goto power_normal;
+ }
+ count += ret;
+ if (count > msgs->len) {
+ /*
+ * The hardware returned too much data.
+ * This is mostly harmless because cp2112_read()
+ * has a limit check so didn't overrun our
+ * buffer. Nevertheless, we return an error
+ * because something is seriously wrong and
+ * it shouldn't go unnoticed.
+ */
+ hid_err(hdev, "long read: %d > %zd\n",
+ ret, msgs->len - count + ret);
+ ret = -EIO;
+ goto power_normal;
+ }
}
finish:
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] HID: cp2112: support large i2c transfers in hid-cp2112
2015-07-08 18:17 [PATCH v3] HID: cp2112: support large i2c transfers in hid-cp2112 Ellen Wang
@ 2015-07-09 12:17 ` Jiri Kosina
2015-07-14 9:58 ` Antonio Borneo
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Kosina @ 2015-07-09 12:17 UTC (permalink / raw)
To: Ellen Wang; +Cc: borneo.antonio, dbarksdale, linux-input, linux-i2c
On Wed, 8 Jul 2015, Ellen Wang wrote:
> cp2112_i2c_xfer() only reads up to 61 bytes, returning EIO
> on longers reads. The fix is to wrap a loop around
> cp2112_read() to pick up all the returned data.
>
> Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
> ---
> This is the updated patch with a check for 0 return from
> cp2112_read(). I tested it with a suitable delay in the loop
> to trigger the cp2112_raw_event() overrun bug, which must
> be fixed before this patch is applied.
Now applied to for-4.3/cp2112 (which is based on for-4.2/upstream-fixes,
where the overrun in ->raw_event() callback is fixed). So please send any
potential updates as followups on top of this patch.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] HID: cp2112: support large i2c transfers in hid-cp2112
2015-07-09 12:17 ` Jiri Kosina
@ 2015-07-14 9:58 ` Antonio Borneo
0 siblings, 0 replies; 3+ messages in thread
From: Antonio Borneo @ 2015-07-14 9:58 UTC (permalink / raw)
To: Jiri Kosina; +Cc: Ellen Wang, David Barksdale, linux-input, linux-i2c
On Thu, Jul 9, 2015 at 8:17 PM, Jiri Kosina <jkosina@suse.com> wrote:
> On Wed, 8 Jul 2015, Ellen Wang wrote:
>
>> cp2112_i2c_xfer() only reads up to 61 bytes, returning EIO
>> on longers reads. The fix is to wrap a loop around
>> cp2112_read() to pick up all the returned data.
>>
>> Signed-off-by: Ellen Wang <ellen@cumulusnetworks.com>
>> ---
>> This is the updated patch with a check for 0 return from
>> cp2112_read(). I tested it with a suitable delay in the loop
>> to trigger the cp2112_raw_event() overrun bug, which must
>> be fixed before this patch is applied.
>
> Now applied to for-4.3/cp2112 (which is based on for-4.2/upstream-fixes,
> where the overrun in ->raw_event() callback is fixed). So please send any
> potential updates as followups on top of this patch.
>
It works as expected.
Either
Tested-by: Antonio Borneo <borneo.antonio@gmail.com>
and/or
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Regards,
Antonio
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-14 9:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-08 18:17 [PATCH v3] HID: cp2112: support large i2c transfers in hid-cp2112 Ellen Wang
2015-07-09 12:17 ` Jiri Kosina
2015-07-14 9:58 ` Antonio Borneo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox