diff options
author | Daniel J. Ogorchock <djogorchock@gmail.com> | 2022-07-13 16:20:59 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2022-08-25 15:15:17 +0200 |
commit | 1ff89e06c2e5fab30274e4b02360d4241d6e605e (patch) | |
tree | dc7971c0d8c3df00467774ef0448d4fd3e2f368c /drivers/hid/hid-nintendo.c | |
parent | 467249a7dff68451868ca79696aef69764193a8a (diff) | |
download | linux-stable-1ff89e06c2e5fab30274e4b02360d4241d6e605e.tar.gz linux-stable-1ff89e06c2e5fab30274e4b02360d4241d6e605e.tar.bz2 linux-stable-1ff89e06c2e5fab30274e4b02360d4241d6e605e.zip |
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 <djogorchock@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-nintendo.c')
-rw-r--r-- | drivers/hid/hid-nintendo.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c index 92ac4f605f13..6028af3c3aae 100644 --- a/drivers/hid/hid-nintendo.c +++ b/drivers/hid/hid-nintendo.c @@ -1221,6 +1221,7 @@ static void joycon_parse_report(struct joycon_ctlr *ctlr, spin_lock_irqsave(&ctlr->lock, flags); if (IS_ENABLED(CONFIG_NINTENDO_FF) && rep->vibrator_report && + ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED && (msecs - ctlr->rumble_msecs) >= JC_RUMBLE_PERIOD_MS && (ctlr->rumble_queue_head != ctlr->rumble_queue_tail || ctlr->rumble_zero_countdown > 0)) { @@ -1545,12 +1546,13 @@ static int joycon_set_rumble(struct joycon_ctlr *ctlr, u16 amp_r, u16 amp_l, ctlr->rumble_queue_head = 0; memcpy(ctlr->rumble_data[ctlr->rumble_queue_head], data, JC_RUMBLE_DATA_SIZE); - spin_unlock_irqrestore(&ctlr->lock, flags); /* don't wait for the periodic send (reduces latency) */ - if (schedule_now) + if (schedule_now && ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED) queue_work(ctlr->rumble_queue, &ctlr->rumble_worker); + spin_unlock_irqrestore(&ctlr->lock, flags); + return 0; } |