Skip to content

Commit e2fa0bd

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Fix set_device_control()
As the search for Device Control report is permissive, make sure the desired field was actually found, before trying to set it. Fix bitmask clearing as it was erronously using index instead of index - 1 (HID arrays index is 1-based). Add last two missing Device Control usages to the defined array. PID_PAUSE and PID_CONTINUE. Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent f98eced commit e2fa0bd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/hid/usbhid/hid-pidff.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 };
118118
#define PID_DISABLE_ACTUATORS 1
119119
#define PID_STOP_ALL_EFFECTS 2
120120
#define PID_RESET 3
121-
static const u8 pidff_device_control[] = { 0x97, 0x98, 0x99, 0x9a };
121+
#define PID_PAUSE 4
122+
#define PID_CONTINUE 5
123+
static const u8 pidff_device_control[] = { 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c };
122124

123125
#define PID_CONSTANT 0
124126
#define PID_RAMP 1
@@ -551,21 +553,29 @@ static void pidff_set_gain_report(struct pidff_device *pidff, u16 gain)
551553
}
552554

553555
/*
554-
* Clear device control report
556+
* Send device control report to the device
555557
*/
556558
static void pidff_set_device_control(struct pidff_device *pidff, int field)
557559
{
558-
int i, tmp;
560+
int i, index;
559561
int field_index = pidff->control_id[field];
560562

563+
if (field_index < 1)
564+
return;
565+
561566
/* Detect if the field is a bitmask variable or an array */
562567
if (pidff->device_control->flags & HID_MAIN_ITEM_VARIABLE) {
563568
hid_dbg(pidff->hid, "DEVICE_CONTROL is a bitmask\n");
569+
564570
/* Clear current bitmask */
565571
for(i = 0; i < sizeof(pidff_device_control); i++) {
566-
tmp = pidff->control_id[i];
567-
pidff->device_control->value[tmp] = 0;
572+
index = pidff->control_id[i];
573+
if (index < 1)
574+
continue;
575+
576+
pidff->device_control->value[index - 1] = 0;
568577
}
578+
569579
pidff->device_control->value[field_index - 1] = 1;
570580
} else {
571581
hid_dbg(pidff->hid, "DEVICE_CONTROL is an array\n");

0 commit comments

Comments
 (0)