From: sashiko-bot@kernel.org
To: "Vicki Pfau" <vi@endrift.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v16 2/4] HID: nintendo: Add rumble support for Switch 2 controllers
Date: Tue, 06 Oct 2026 06:30:01 +0000 [thread overview]
Message-ID: <20261006063001.EEE2C1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261006061619.2005967-3-vi@endrift.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] hid: nintendo: Use-after-free of ns2 in rumble_work due to missing sync cancel
- [High] hid: nintendo: Workqueue list corruption due to rumble_work re-initialization
--
commit a197b51ef6afbdd0338765f77b38c7488b6d41fe
Author: Vicki Pfau <vi@endrift.com>
HID: nintendo: Add rumble support for Switch 2 controllers
This commit adds basic rumble support for Switch 2 controllers,
simulating standard force feedback using the HD Rumble actuators.
It introduces a delayed work item to manage rumble state updates.
> diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
> index c31ded267be76..c49ca95753206 100644
> --- a/drivers/hid/hid-nintendo.c
> +++ b/drivers/hid/hid-nintendo.c
[ ... ]
> @@ -3374,6 +3550,26 @@ static int switch2_init_input(struct switch2_controller *ns2)
> return -EINVAL;
> }
>
> +#if IS_ENABLED(CONFIG_NINTENDO_FF)
> + ns2->rumble_buffer = devm_kzalloc(&input->dev, 64, GFP_KERNEL);
> + if (!ns2->rumble_buffer) {
> + input_free_device(input);
> + return -ENOMEM;
> + }
> + ret = devm_delayed_work_autocancel(&input->dev, &ns2->rumble_work, switch2_rumble_work);
[Severity: High]
Can this lead to a use-after-free of the ns2 structure?
The devm_delayed_work_autocancel() helper binds the work cancellation to
the input device's devres group. If a userspace process holds the input
device open when the physical device is unplugged, the devres execution is
delayed until the file descriptor is closed. However, the driver's remove
function frees the ns2 controller structure synchronously via kref_put()
without waiting for the devres cleanup. If the delayed work is pending,
it will execute and access the freed ns2 structure in switch2_rumble_work().
[Severity: High]
Does this code corrupt the workqueue list if initialization is retried?
In switch2_init_input(), the input device is registered and exposed to
userspace. If a subsequent initialization step fails, such as the LED
registration, the error path unregisters the device. If userspace opens
the device and triggers a rumble effect before unregistration completes,
ns2->rumble_work is queued.
The state machine then retries switch2_init_controller(), which calls
switch2_init_input() again. This allocates a new input device and calls
devm_delayed_work_autocancel() on the exact same &ns2->rumble_work. This
unconditionally calls INIT_DELAYED_WORK() on an already-queued work item,
which overwrites its list pointers and corrupts the workqueue list.
> + if (ret < 0) {
> + input_free_device(input);
> + return ret;
> + }
> +
> + input_set_capability(input, EV_FF, FF_RUMBLE);
> + ret = input_ff_create_memless(input, NULL, switch2_play_effect);
> + if (ret) {
> + input_free_device(input);
> + return ret;
> + }
> +#endif
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261006061619.2005967-1-vi@endrift.com?part=2
next prev parent reply other threads:[~2026-10-06 6:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 6:16 [PATCH v16 0/4] HID: nintendo: Add preliminary Switch 2 controller driver Vicki Pfau
2026-10-06 6:16 ` [PATCH v16 1/4] " Vicki Pfau
2026-10-06 6:30 ` sashiko-bot
2026-10-06 6:16 ` [PATCH v16 2/4] HID: nintendo: Add rumble support for Switch 2 controllers Vicki Pfau
2026-10-06 6:30 ` sashiko-bot [this message]
2026-10-06 6:16 ` [PATCH v16 3/4] HID: nintendo: Add unified report format support Vicki Pfau
2026-10-06 6:16 ` [PATCH v16 4/4] HID: nintendo: Patch NYXI Hyperion 3 descriptor 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=20261006063001.EEE2C1F00893@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