2015-06-21 06:20:51

by Antonio Borneo

[permalink] [raw]
Subject: [PATCH] HID: cp2112: fix to force single data-report reply

Current implementation of cp2112_raw_event() only accepts one data
report at a time. If last received data report is not fully handled
yet, a new incoming data report will overwrite it. In such case we
don't guaranteed to propagate the correct incoming data.

The trivial fix implemented here forces a single report at a time
by requesting in cp2112_read() no more than 61 byte of data, which
is the payload size of a single data report.

Signed-off-by: Antonio Borneo <[email protected]>
---

Hi Jiri,

I think this should go through linux-stable.

Thanks,
Antonio

drivers/hid/hid-cp2112.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 3318de6..a2dbbbe 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -356,6 +356,8 @@ static int cp2112_read(struct cp2112_device *dev, u8 *data, size_t size)
struct cp2112_force_read_report report;
int ret;

+ if (size > sizeof(dev->read_data))
+ size = sizeof(dev->read_data);
report.report = CP2112_DATA_READ_FORCE_SEND;
report.length = cpu_to_be16(size);

--
2.4.4


2015-07-01 08:05:39

by Ellen Wang

[permalink] [raw]
Subject: Re: [PATCH] HID: cp2112: fix to force single data-report reply

Works as described. Thank you!

By the way, I tested the code with and without your fix on my rev 2
chip, and it behaved the same way as you describe on your rev 1 chip.

On 06/20/2015 11:20 PM, Antonio Borneo wrote:
> Current implementation of cp2112_raw_event() only accepts one data
> report at a time. If last received data report is not fully handled
> yet, a new incoming data report will overwrite it. In such case we
> don't guaranteed to propagate the correct incoming data.
>
> The trivial fix implemented here forces a single report at a time
> by requesting in cp2112_read() no more than 61 byte of data, which
> is the payload size of a single data report.
>
> Signed-off-by: Antonio Borneo <[email protected]>
> ---
>
> Hi Jiri,
>
> I think this should go through linux-stable.
>
> Thanks,
> Antonio
>
> drivers/hid/hid-cp2112.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
> index 3318de6..a2dbbbe 100644
> --- a/drivers/hid/hid-cp2112.c
> +++ b/drivers/hid/hid-cp2112.c
> @@ -356,6 +356,8 @@ static int cp2112_read(struct cp2112_device *dev, u8 *data, size_t size)
> struct cp2112_force_read_report report;
> int ret;
>
> + if (size > sizeof(dev->read_data))
> + size = sizeof(dev->read_data);
> report.report = CP2112_DATA_READ_FORCE_SEND;
> report.length = cpu_to_be16(size);
>
>

2015-07-08 09:15:57

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] HID: cp2112: fix to force single data-report reply

On Wed, 1 Jul 2015, Ellen Wang wrote:

> Works as described. Thank you!
>
> By the way, I tested the code with and without your fix on my rev 2 chip, and
> it behaved the same way as you describe on your rev 1 chip.

Ellen, are you okay with me applying the patch with

Tested-by: Ellen Wang <[email protected]>

?

Thanks,

--
Jiri Kosina
SUSE Labs

2015-07-08 10:24:49

by Ellen Wang

[permalink] [raw]
Subject: Re: [PATCH] HID: cp2112: fix to force single data-report reply

On 07/08/2015 02:15 AM, Jiri Kosina wrote:
> On Wed, 1 Jul 2015, Ellen Wang wrote:
>
>> Works as described. Thank you!
>>
>> By the way, I tested the code with and without your fix on my rev 2 chip, and
>> it behaved the same way as you describe on your rev 1 chip.
>
> Ellen, are you okay with me applying the patch with
>
> Tested-by: Ellen Wang <[email protected]>
>
> ?
>
> Thanks,

Yes. Thank you.

2015-07-08 10:41:31

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH] HID: cp2112: fix to force single data-report reply

On Wed, 8 Jul 2015, Ellen Wang wrote:

> > > Works as described. Thank you!
> > >
> > > By the way, I tested the code with and without your fix on my rev 2 chip,
> > > and
> > > it behaved the same way as you describe on your rev 1 chip.
> >
> > Ellen, are you okay with me applying the patch with
> >
> > Tested-by: Ellen Wang <[email protected]>
> >
> > ?
> >
> > Thanks,
>
> Yes. Thank you.

Ammended with Cc: stable tag, and applied to for-4.2/upstream-fixes.
Thanks,

--
Jiri Kosina
SUSE Labs

2015-07-11 11:48:47

by Antonio Borneo

[permalink] [raw]
Subject: Re: [PATCH] HID: cp2112: fix to force single data-report reply

On Wed, Jul 8, 2015 at 6:41 PM, Jiri Kosina <[email protected]> wrote:
> On Wed, 8 Jul 2015, Ellen Wang wrote:
>
>> > > Works as described. Thank you!
>> > >
>> > > By the way, I tested the code with and without your fix on my rev 2 chip,
>> > > and
>> > > it behaved the same way as you describe on your rev 1 chip.
>> >
>> > Ellen, are you okay with me applying the patch with
>> >
>> > Tested-by: Ellen Wang <[email protected]>
>> >
>> > ?
>> >
>> > Thanks,
>>
>> Yes. Thank you.
>
> Ammended with Cc: stable tag, and applied to for-4.2/upstream-fixes.
> Thanks,

Thanks!

Antonio