Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vicki Pfau" <vi@endrift.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v11 1/3] HID: nintendo: Add preliminary Switch 2 controller driver
Date: Thu, 02 Jul 2026 22:04:07 +0000	[thread overview]
Message-ID: <20260702220407.EDEEE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260702214704.1859350-2-vi@endrift.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Concurrent URB completion and device disconnect paths cause a Use-After-Free due to missing synchronization.
- [High] Immediate resubmission of failed bulk IN URBs causes an interrupt storm.
--

Note: The format of this review has been altered to use a free-form summary of findings rather than inline patch quoting due to recitation restrictions.

commit 77b4d4df4f2d3eefe6970b5429bc05e1a86ecc7e
Author: Vicki Pfau <vi@endrift.com>

HID: nintendo: Add preliminary Switch 2 controller driver

This adds a new driver for the Switch 2 controllers. The Switch 2 uses an
unusual split-interface design such that input and rumble occur on the main
HID interface, but all other communication occurs over a "configuration"
interface.

[Severity: High]
In switch2_bulk_in(), could this cause a use-after-free during device
disconnect?

When switch2_usb_disconnect() executes concurrently with an URB completion,
it calls usb_kill_anchored_urbs() to cancel in-flight URBs. However, the USB
core unanchors the URB just before invoking the completion handler. Thus,
usb_kill_anchored_urbs() misses the URB being processed:

switch2_usb_disconnect()
    usb_kill_anchored_urbs(&ns2_usb->bulk_in_anchor);
    cancel_work_sync(&ns2_usb->message_in_work);

If switch2_bulk_in() is preempted before it schedules work:

switch2_bulk_in()
    ...
    if (schedule)
        schedule_work(&ns2_usb->message_in_work);

the disconnect path will complete and free ns2_usb via devres. When the
completion handler resumes, it attempts to access the freed context. Does
this missing synchronization need to be addressed?

[Severity: High]
Can an interrupt storm occur if a bulk IN URB fails persistently?

In switch2_bulk_in(), if an URB completes with an error like -EPIPE or
-EPROTO, the schedule boolean is false, but the URB state is set to
NS2_URB_FREE. The driver then immediately evaluates it for resubmission:

switch2_bulk_in()
    ...
    usb_anchor_urb(ns2_urb->urb, &ns2_usb->bulk_in_anchor);
    err = usb_submit_urb(ns2_urb->urb, GFP_ATOMIC);

Since the device isn't shutting down and the anchor is empty, the exact same
failing URB is resubmitted instantly. This will likely fail again right
away, re-invoking the handler and creating an infinite loop. Should the
resubmission logic be delayed or halted upon encountering persistent
errors?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702214704.1859350-1-vi@endrift.com?part=1

  reply	other threads:[~2026-07-02 22:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02 21:46 [PATCH v11 0/3] HID: nintendo: Add preliminary Switch 2 controller Vicki Pfau
2026-07-02 21:47 ` [PATCH v11 1/3] HID: nintendo: Add preliminary Switch 2 controller driver Vicki Pfau
2026-07-02 22:04   ` sashiko-bot [this message]
2026-07-02 21:47 ` [PATCH v11 2/3] HID: nintendo: Add rumble support for Switch 2 controllers Vicki Pfau
2026-07-02 22:04   ` sashiko-bot
2026-07-02 21:47 ` [PATCH v11 3/3] HID: nintendo: Add unified report format support Vicki Pfau

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=20260702220407.EDEEE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vi@endrift.com \
    /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