Skip to content

Commit 5eae59c

Browse files
ian-abbottJiri Kosina
authored andcommitted
HID: wiimote: narrow spinlock range in wiimote_hid_event()
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 <[email protected]> Reviewed-by: David Rheinsberg <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent aeeba45 commit 5eae59c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/hid/hid-wiimote-core.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,12 +1625,12 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
16251625
if (size < 1)
16261626
return -EINVAL;
16271627

1628-
spin_lock_irqsave(&wdata->state.lock, flags);
1629-
16301628
for (i = 0; handlers[i].id; ++i) {
16311629
h = &handlers[i];
16321630
if (h->id == raw_data[0] && h->size < size) {
1631+
spin_lock_irqsave(&wdata->state.lock, flags);
16331632
h->func(wdata, &raw_data[1]);
1633+
spin_unlock_irqrestore(&wdata->state.lock, flags);
16341634
break;
16351635
}
16361636
}
@@ -1639,8 +1639,6 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
16391639
hid_warn(hdev, "Unhandled report %hhu size %d\n", raw_data[0],
16401640
size);
16411641

1642-
spin_unlock_irqrestore(&wdata->state.lock, flags);
1643-
16441642
return 0;
16451643
}
16461644

0 commit comments

Comments
 (0)