From ad8d3b91e48e1d9b7f94a5cc46cd6e4fd58dc6f5 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 26 Jul 2026 22:07:59 -0700 Subject: [PATCH] Input: psmouse - clean up locking around disable_work_sync() In the past, psmouse_disconnect() used cancel_work_sync(). Because cancel_work_sync() must be called with the psmouse_mutex dropped, and we needed to prevent psmouse_receive_byte() from re-queueing the work behind our back, the code transitioned the device to PSMOUSE_CMD_MODE while holding the mutex, then dropped the mutex and cancelled the work. When cancel_work_sync() was replaced with disable_work_sync() in this path, the mutex juggling remained. However, disable_work_sync() inherently prevents the work from being executed or re-queued, making the mutex juggling unnecessary. Clean this up by moving disable_work_sync() to the very top of psmouse_disconnect(), before we acquire psmouse_mutex. Assisted-by: Antigravity:gemini-3.5-flash Link: https://patch.msgid.link/20260727050803.1269941-2-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/psmouse-base.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index 108591b7ebf3..668a6a4fbe82 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -1460,15 +1460,12 @@ static void psmouse_disconnect(struct serio *serio) struct psmouse *psmouse = psmouse_from_serio(serio); struct psmouse *parent = NULL; + disable_work_sync(&psmouse->resync_work); + mutex_lock(&psmouse_mutex); psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); - /* make sure we don't have a resync in progress */ - mutex_unlock(&psmouse_mutex); - disable_work_sync(&psmouse->resync_work); - mutex_lock(&psmouse_mutex); - if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { parent = psmouse_from_serio(serio->parent); psmouse_deactivate(parent);