Skip to content

Commit 1ff89e0

Browse files
DanielOgorchockJiri Kosina
authored andcommitted
HID: nintendo: fix rumble worker null pointer deref
We can dereference a null pointer trying to queue work to a destroyed workqueue. If the device is disconnected, nintendo_hid_remove is called, in which the rumble_queue is destroyed. Avoid using that queue to defer rumble work once the controller state is set to JOYCON_CTLR_STATE_REMOVED. This eliminates the null pointer dereference. Signed-off-by: Daniel J. Ogorchock <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 467249a commit 1ff89e0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/hid/hid-nintendo.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ static void joycon_parse_report(struct joycon_ctlr *ctlr,
12211221

12221222
spin_lock_irqsave(&ctlr->lock, flags);
12231223
if (IS_ENABLED(CONFIG_NINTENDO_FF) && rep->vibrator_report &&
1224+
ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED &&
12241225
(msecs - ctlr->rumble_msecs) >= JC_RUMBLE_PERIOD_MS &&
12251226
(ctlr->rumble_queue_head != ctlr->rumble_queue_tail ||
12261227
ctlr->rumble_zero_countdown > 0)) {
@@ -1545,12 +1546,13 @@ static int joycon_set_rumble(struct joycon_ctlr *ctlr, u16 amp_r, u16 amp_l,
15451546
ctlr->rumble_queue_head = 0;
15461547
memcpy(ctlr->rumble_data[ctlr->rumble_queue_head], data,
15471548
JC_RUMBLE_DATA_SIZE);
1548-
spin_unlock_irqrestore(&ctlr->lock, flags);
15491549

15501550
/* don't wait for the periodic send (reduces latency) */
1551-
if (schedule_now)
1551+
if (schedule_now && ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED)
15521552
queue_work(ctlr->rumble_queue, &ctlr->rumble_worker);
15531553

1554+
spin_unlock_irqrestore(&ctlr->lock, flags);
1555+
15541556
return 0;
15551557
}
15561558

0 commit comments

Comments
 (0)