HID: pidff: Fix set_device_control()
authorTomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
Tue, 25 Feb 2025 22:30:04 +0000 (23:30 +0100)
committerJiri Kosina <jkosina@suse.com>
Tue, 4 Mar 2025 20:42:44 +0000 (21:42 +0100)
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>
drivers/hid/usbhid/hid-pidff.c

index 6eb7934c8f53bc6c801c6964f3f88ea497001331..8dfd2c554a27627169182dbbe0a5ae48523b4354 100644 (file)
@@ -118,7 +118,9 @@ static const u8 pidff_pool[] = { 0x80, 0x83, 0xa9 };
 #define PID_DISABLE_ACTUATORS  1
 #define PID_STOP_ALL_EFFECTS   2
 #define PID_RESET              3
-static const u8 pidff_device_control[] = { 0x97, 0x98, 0x99, 0x9a };
+#define PID_PAUSE              4
+#define PID_CONTINUE           5
+static const u8 pidff_device_control[] = { 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c };
 
 #define PID_CONSTANT   0
 #define PID_RAMP       1
@@ -551,21 +553,29 @@ static void pidff_set_gain_report(struct pidff_device *pidff, u16 gain)
 }
 
 /*
- * Clear device control report
+ * Send device control report to the device
  */
 static void pidff_set_device_control(struct pidff_device *pidff, int field)
 {
-       int i, tmp;
+       int i, index;
        int field_index = pidff->control_id[field];
 
+       if (field_index < 1)
+               return;
+
        /* Detect if the field is a bitmask variable or an array */
        if (pidff->device_control->flags & HID_MAIN_ITEM_VARIABLE) {
                hid_dbg(pidff->hid, "DEVICE_CONTROL is a bitmask\n");
+
                /* Clear current bitmask */
                for(i = 0; i < sizeof(pidff_device_control); i++) {
-                       tmp = pidff->control_id[i];
-                       pidff->device_control->value[tmp] = 0;
+                       index = pidff->control_id[i];
+                       if (index < 1)
+                               continue;
+
+                       pidff->device_control->value[index - 1] = 0;
                }
+
                pidff->device_control->value[field_index - 1] = 1;
        } else {
                hid_dbg(pidff->hid, "DEVICE_CONTROL is an array\n");