Skip to content

Commit e01a029

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Do not set out of range trigger button
Some games (mainly observed with Kylotonn's WRC Serises) set trigger button to a random value, or always the same one, out of range. I observed 307 and other values but, for example, my Moza R9 only exposes 128 buttons AND it's trigger button field is 8-bit. This causes errors to appear in dmesg. Only set the trigger button and trigger interval in the trigger button is in range of the field. Signed-off-by: Tomasz Pakuła <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 79b95d7 commit e01a029

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

drivers/hid/usbhid/hid-pidff.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,19 @@ static void pidff_set_effect_report(struct pidff_device *pidff,
523523
pidff_set_duration(&pidff->set_effect[PID_DURATION],
524524
effect->replay.length);
525525

526-
pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = effect->trigger.button;
527-
pidff_set_time(&pidff->set_effect[PID_TRIGGER_REPEAT_INT],
528-
effect->trigger.interval);
526+
/* Some games set this to random values that can be out of range */
527+
s32 trigger_button_max =
528+
pidff->set_effect[PID_TRIGGER_BUTTON].field->logical_maximum;
529+
if (effect->trigger.button <= trigger_button_max) {
530+
pidff->set_effect[PID_TRIGGER_BUTTON].value[0] =
531+
effect->trigger.button;
532+
pidff_set_time(&pidff->set_effect[PID_TRIGGER_REPEAT_INT],
533+
effect->trigger.interval);
534+
} else {
535+
pidff->set_effect[PID_TRIGGER_BUTTON].value[0] = 0;
536+
pidff->set_effect[PID_TRIGGER_REPEAT_INT].value[0] = 0;
537+
}
538+
529539
pidff->set_effect[PID_GAIN].value[0] =
530540
pidff->set_effect[PID_GAIN].field->logical_maximum;
531541

0 commit comments

Comments
 (0)