]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
HID: pidff: Factor out pool report fetch and remove excess declaration
authorTomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
Sat, 1 Feb 2025 11:39:06 +0000 (12:39 +0100)
committerJiri Kosina <jkosina@suse.com>
Mon, 3 Feb 2025 14:17:11 +0000 (15:17 +0100)
We only want to refetch the pool report during device init. Reset
function is now called when uploading effects to an empty device so
extract pool fetch to separate function and call it from init before
autocenter check (autocenter check triggered reset during init).

Remove a superfluous pointer declaration and assigment as well.

Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
Reviewed-by: Michał Kopeć <michal@nozomi.space>
Reviewed-by: Paul Dino Jones <paul@spacefreak18.xyz>
Tested-by: Paul Dino Jones <paul@spacefreak18.xyz>
Tested-by: Cristóferson Bueno <cbueno81@gmail.com>
Tested-by: Pablo Cisneros <patchkez@protonmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/usbhid/hid-pidff.c

index b21e844f5f3a3179993fc6db249a3113726d1ba9..f23381b6e3447921c87db52b599121807bb7c4b0 100644 (file)
@@ -591,12 +591,9 @@ static void pidff_modify_actuators_state(struct pidff_device *pidff, bool enable
 
 /*
  * Reset the device, stop all effects, enable actuators
- * Refetch pool report
  */
 static void pidff_reset(struct pidff_device *pidff)
 {
-       int i = 0;
-
        /* We reset twice as sometimes hid_wait_io isn't waiting long enough */
        pidff_send_device_control(pidff, PID_RESET);
        pidff_send_device_control(pidff, PID_RESET);
@@ -604,23 +601,29 @@ static void pidff_reset(struct pidff_device *pidff)
 
        pidff_send_device_control(pidff, PID_STOP_ALL_EFFECTS);
        pidff_modify_actuators_state(pidff, 1);
+}
 
-       /* pool report is sometimes messed up, refetch it */
-       hid_hw_request(pidff->hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT);
-       hid_hw_wait(pidff->hid);
+/*
+ * Refetch pool report
+ */
+static void pidff_fetch_pool(struct pidff_device *pidff)
+{
+       if (!pidff->pool[PID_SIMULTANEOUS_MAX].value)
+               return;
 
-       if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
-               while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
-                       if (i++ > 20) {
-                               hid_warn(pidff->hid,
-                                        "device reports %d simultaneous effects\n",
-                                        pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
-                               break;
-                       }
-                       hid_dbg(pidff->hid, "pid_pool requested again\n");
-                       hid_hw_request(pidff->hid, pidff->reports[PID_POOL],
-                                         HID_REQ_GET_REPORT);
-                       hid_hw_wait(pidff->hid);
+       int i = 0;
+       while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
+               hid_dbg(pidff->hid, "pid_pool requested again\n");
+               hid_hw_request(pidff->hid, pidff->reports[PID_POOL],
+                               HID_REQ_GET_REPORT);
+               hid_hw_wait(pidff->hid);
+
+               /* break after 20 tries with SIMULTANEOUS_MAX < 2 */
+               if (i++ > 20) {
+                       hid_warn(pidff->hid,
+                                "device reports %d simultaneous effects\n",
+                                pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
+                       break;
                }
        }
 }
@@ -916,9 +919,7 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
  */
 static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
 {
-       struct pidff_device *pidff = dev->ff->private;
-
-       pidff_autocenter(pidff, magnitude);
+       pidff_autocenter(dev->ff->private, magnitude);
 }
 
 /*
@@ -1424,6 +1425,8 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, u32 initial_quirks)
        if (error)
                goto fail;
 
+       /* pool report is sometimes messed up, refetch it */
+       pidff_fetch_pool(pidff);
        pidff_set_gain_report(pidff, U16_MAX);
        error = pidff_check_autocenter(pidff, dev);
        if (error)