Skip to content

Commit 1f650dc

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Make sure to fetch pool before checking SIMULTANEOUS_MAX
As noted by Anssi some 20 years ago, pool report is sometimes messed up. This worked fine on many devices but casued oops on VRS DirectForce PRO. Here, we're making sure pool report is refetched before trying to access any of it's fields. While loop was replaced with a for loop + exit conditions were moved aroud to decrease the possibility of creating an infinite loop scenario. Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 2c2afb5 commit 1f650dc

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

drivers/hid/usbhid/hid-pidff.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -604,28 +604,25 @@ static void pidff_reset(struct pidff_device *pidff)
604604
}
605605

606606
/*
607-
* Refetch pool report
607+
* Fetch pool report
608608
*/
609609
static void pidff_fetch_pool(struct pidff_device *pidff)
610610
{
611-
if (!pidff->pool[PID_SIMULTANEOUS_MAX].value)
612-
return;
611+
int i;
612+
struct hid_device *hid = pidff->hid;
613613

614-
int i = 0;
615-
while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
616-
hid_dbg(pidff->hid, "pid_pool requested again\n");
617-
hid_hw_request(pidff->hid, pidff->reports[PID_POOL],
618-
HID_REQ_GET_REPORT);
619-
hid_hw_wait(pidff->hid);
614+
/* Repeat if PID_SIMULTANEOUS_MAX < 2 to make sure it's correct */
615+
for(i = 0; i < 20; i++) {
616+
hid_hw_request(hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT);
617+
hid_hw_wait(hid);
620618

621-
/* break after 20 tries with SIMULTANEOUS_MAX < 2 */
622-
if (i++ > 20) {
623-
hid_warn(pidff->hid,
624-
"device reports %d simultaneous effects\n",
625-
pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
626-
break;
627-
}
619+
if (!pidff->pool[PID_SIMULTANEOUS_MAX].value)
620+
return;
621+
if (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] >= 2)
622+
return;
628623
}
624+
hid_warn(hid, "device reports %d simultaneous effects\n",
625+
pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
629626
}
630627

631628
/*

0 commit comments

Comments
 (0)