From: Vicki Pfau <vi@endrift.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
linux-input@vger.kernel.org
Cc: Vicki Pfau <vi@endrift.com>,
Noah Weinberger <noahweinberger2003@proton.me>
Subject: [PATCH 2/2] HID: nintendo-switch2-usb: Improve shutdown logic with inbound message work
Date: Tue, 10 Nov 2026 19:20:32 -0800 [thread overview]
Message-ID: <20261111032125.2888320-2-vi@endrift.com> (raw)
In-Reply-To: <20261111032125.2888320-1-vi@endrift.com>
When detaching the USB interface the driver marks the interface as shutdown
to prevent work that may be executing in parallel from attempting to use
the URBs before freeing the URBs. There is theoretically a very narrow
window in which the work could be scheduled while the shutdown is running
in a separate thread, starting to execute before the shutdown cancels the
work.
By ensuring the scheduling happens within the locked scope and adding an
additional shutdown check, this closes the window entirely.
Reported-by: Noah Weinberger <noahweinberger2003@proton.me>
Link: https://lore.kernel.org/linux-input/a2dc00e7-9cab-4315-87a4-795f256c1e03@endrift.com/T/
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 | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/hid/hid-nintendo-switch2-usb.c b/drivers/hid/hid-nintendo-switch2-usb.c
index d747000336dc..5dba25c738e1 100644
--- a/drivers/hid/hid-nintendo-switch2-usb.c
+++ b/drivers/hid/hid-nintendo-switch2-usb.c
@@ -52,12 +52,10 @@ static void switch2_bulk_in(struct urb *urb)
{
struct switch2_usb *ns2_usb = urb->context;
int i;
- bool schedule = false;
unsigned long flags;
switch (urb->status) {
case 0:
- schedule = true;
break;
case -ECONNRESET:
case -ENOENT:
@@ -71,16 +69,14 @@ static void switch2_bulk_in(struct urb *urb)
}
spin_lock_irqsave(&ns2_usb->bulk_in_lock, flags);
- if (ns2_usb->shutdown)
- schedule = false;
-
for (i = 0; i < NS2_IN_URBS; i++) {
int err;
struct switch2_urb *ns2_urb;
if (ns2_usb->bulk_in[i].urb == urb) {
- if (schedule) {
+ if (urb->status == 0 && !ns2_usb->shutdown) {
ns2_usb->bulk_in[i].state = NS2_URB_IN;
+ schedule_work(&ns2_usb->message_in_work);
continue;
} else {
ns2_usb->bulk_in[i].state = NS2_URB_FREE;
@@ -115,9 +111,6 @@ static void switch2_bulk_in(struct urb *urb)
}
}
spin_unlock_irqrestore(&ns2_usb->bulk_in_lock, flags);
-
- if (schedule)
- schedule_work(&ns2_usb->message_in_work);
}
static void switch2_bulk_out(struct urb *urb)
@@ -294,6 +287,10 @@ static void switch2_usb_message_in_work(struct work_struct *work)
unsigned long flags;
spin_lock_irqsave(&ns2_usb->bulk_in_lock, flags);
+ if (ns2_usb->shutdown) {
+ spin_unlock_irqrestore(&ns2_usb->bulk_in_lock, flags);
+ return;
+ }
for (i = 0; i < NS2_IN_URBS; i++) {
urb = &ns2_usb->bulk_in[i];
if (urb->state != NS2_URB_IN)
--
2.54.0
next prev parent reply other threads:[~2026-11-11 3:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 3:20 [PATCH 1/2] HID: nintendo-switch2-usb: Fix potential deadlock on teardown Vicki Pfau
2026-11-11 3:20 ` Vicki Pfau [this message]
2026-11-11 3:37 ` [PATCH 2/2] HID: nintendo-switch2-usb: Improve shutdown logic with inbound message work sashiko-bot
2026-11-11 3:37 ` [PATCH 1/2] HID: nintendo-switch2-usb: Fix potential deadlock on teardown sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261111032125.2888320-2-vi@endrift.com \
--to=vi@endrift.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=noahweinberger2003@proton.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox