]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
HID: wiimote: narrow spinlock range in wiimote_hid_event()
authorIan Abbott <abbotti@mev.co.uk>
Fri, 4 Sep 2020 13:21:43 +0000 (14:21 +0100)
committerJiri Kosina <jkosina@suse.cz>
Mon, 7 Sep 2020 14:03:51 +0000 (16:03 +0200)
In `wiimote_hid_event()`, the `wdata->state.lock` spinlock does not need
to be held while searching `handlers[]` for a suitable handler function.
Change it so the spinlock is only held during the call to the handler
function itself.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: David Rheinsberg <david.rheinsberg@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-wiimote-core.c

index e03a0ba5611a62fc5a856d26fb2e0bd82b445f2c..41012681cafd1ec469d9bfb19930cf1d4a5c6d00 100644 (file)
@@ -1625,12 +1625,12 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
        if (size < 1)
                return -EINVAL;
 
-       spin_lock_irqsave(&wdata->state.lock, flags);
-
        for (i = 0; handlers[i].id; ++i) {
                h = &handlers[i];
                if (h->id == raw_data[0] && h->size < size) {
+                       spin_lock_irqsave(&wdata->state.lock, flags);
                        h->func(wdata, &raw_data[1]);
+                       spin_unlock_irqrestore(&wdata->state.lock, flags);
                        break;
                }
        }
@@ -1639,8 +1639,6 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
                hid_warn(hdev, "Unhandled report %hhu size %d\n", raw_data[0],
                                                                        size);
 
-       spin_unlock_irqrestore(&wdata->state.lock, flags);
-
        return 0;
 }