Skip to content

Commit 315a183

Browse files
committed
drivers/cps-hid.c: cps_fix_report_desc(): take the higher ground [#2718]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent b249c99 commit 315a183

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/cps-hid.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,18 @@ static int cps_fix_report_desc(HIDDevice_t *pDev, HIDDesc_t *pDesc_arg) {
453453
&& input_pData->Size > 1
454454
&& input_pData->Size <= sizeof(long)*8
455455
) {
456-
/* Note: values are signed, so limit by
457-
* 2^(size-1)-1, e.g. for "size==16" the
458-
* limit should be "2^15 - 1 = 32767";
456+
/* Note: usually values are signed, but
457+
* here we are about compensating for
458+
* poorly encoded maximums, so limit by
459+
* 2^(size)-1, e.g. for "size==16" the
460+
* limit should be "2^16 - 1 = 65535";
459461
* note that in HIDParse() we likely
460462
* set 65535 here in that case. See
461-
* also comments there (hidparser.c).
463+
* also comments there (hidparser.c)
464+
* discussing signed/unsigned nuances.
462465
*/
463-
long sizeMax = (1L << (input_pData->Size - 1)) - 1;
466+
/* long sizeMax = (1L << (input_pData->Size - 1)) - 1; */
467+
long sizeMax = (1L << (input_pData->Size)) - 1;
464468
if (input_logmax > sizeMax) {
465469
input_logmax = sizeMax;
466470
}
@@ -471,7 +475,8 @@ static int cps_fix_report_desc(HIDDevice_t *pDev, HIDDesc_t *pDesc_arg) {
471475
&& output_pData->Size <= sizeof(long)*8
472476
) {
473477
/* See comment above */
474-
long sizeMax = (1L << (output_pData->Size - 1)) - 1;
478+
/* long sizeMax = (1L << (output_pData->Size - 1)) - 1; */
479+
long sizeMax = (1L << (output_pData->Size)) - 1;
475480
if (output_logmax > sizeMax) {
476481
output_logmax = sizeMax;
477482
}

0 commit comments

Comments
 (0)