Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH 1/2] HID: nintendo-switch2-usb: Fix potential deadlock on teardown
@ 2026-11-11  3:20 Vicki Pfau
  2026-11-11  3:20 ` [PATCH 2/2] HID: nintendo-switch2-usb: Improve shutdown logic with inbound message work Vicki Pfau
  2026-11-11  3:37 ` [PATCH 1/2] HID: nintendo-switch2-usb: Fix potential deadlock on teardown sashiko-bot
  0 siblings, 2 replies; 4+ messages in thread
From: Vicki Pfau @ 2026-11-11  3:20 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, linux-input; +Cc: Vicki Pfau, Sashiko

As reported by Sashiko, there is a narrow window in which cancel_work_sync
on the message in work can block due to the work waiting on the mutex that
the canceling thread holds. We work around this by replacing it with a
non-sync cancel and a sync cancel later on, to ensure it's actually exited.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/message/20261006063000.A0B821F000FF%40smtp.kernel.org
Fixes: 9417132df63e ("HID: nintendo: Add preliminary Switch 2 controller driver")
Signed-off-by: Vicki Pfau <vi@endrift.com>
---
 drivers/hid/hid-nintendo-switch2-usb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-nintendo-switch2-usb.c b/drivers/hid/hid-nintendo-switch2-usb.c
index 8b3b6841035d..d747000336dc 100644
--- a/drivers/hid/hid-nintendo-switch2-usb.c
+++ b/drivers/hid/hid-nintendo-switch2-usb.c
@@ -217,7 +217,7 @@ static void switch2_usb_free_in_urbs(struct switch2_usb *ns2_usb)
 	ns2_usb->shutdown = true;
 	spin_unlock_irqrestore(&ns2_usb->bulk_in_lock, flags);
 
-	cancel_work_sync(&ns2_usb->message_in_work);
+	cancel_work(&ns2_usb->message_in_work);
 
 	usb_kill_anchored_urbs(&ns2_usb->bulk_in_anchor);
 	for (i = 0; i < NS2_IN_URBS; i++) {
@@ -276,7 +276,7 @@ static void switch2_usb_shutdown(struct switch2_cfg_intf *intf)
 	ns2_usb->shutdown = true;
 	spin_unlock_irqrestore(&ns2_usb->bulk_in_lock, flags);
 
-	cancel_work_sync(&ns2_usb->message_in_work);
+	cancel_work(&ns2_usb->message_in_work);
 
 	usb_kill_anchored_urbs(&ns2_usb->bulk_in_anchor);
 	spin_lock_irqsave(&ns2_usb->bulk_in_lock, flags);
@@ -447,6 +447,7 @@ static int switch2_usb_probe(struct usb_interface *intf, const struct usb_device
 	switch2_usb_free_out_urbs(ns2_usb);
 err_free_in:
 	switch2_usb_free_in_urbs(ns2_usb);
+	cancel_work_sync(&ns2_usb->message_in_work);
 	devm_kfree(&intf->dev, ns2_usb);
 
 	return ret;
@@ -466,6 +467,8 @@ static void switch2_usb_disconnect(struct usb_interface *intf)
 		switch2_controller_detach_cfg(ns2_usb->cfg.parent);
 
 	switch2_usb_free_out_urbs(ns2_usb);
+
+	cancel_work_sync(&ns2_usb->message_in_work);
 }
 
 #define SWITCH2_CONTROLLER(vend, prod) \
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-11  3:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  3:20 [PATCH 1/2] HID: nintendo-switch2-usb: Fix potential deadlock on teardown Vicki Pfau
2026-11-11  3:20 ` [PATCH 2/2] HID: nintendo-switch2-usb: Improve shutdown logic with inbound message work Vicki Pfau
2026-11-11  3:37   ` sashiko-bot
2026-11-11  3:37 ` [PATCH 1/2] HID: nintendo-switch2-usb: Fix potential deadlock on teardown sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox