mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "René Onier" <f3nr1l@me.com>
To: Benjamin Tissoires <bentiss@kernel.org>, Jiri Kosina <jikos@kernel.org>
Cc: "René Onier" <f3nr1l@me.com>,
	"Ivan Gorinov" <linux-kernel@altimeter.info>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Subject: [PATCH 0/2] HID: winwing: two teardown fixes
Date: Wed, 30 Sep 2026 15:37:49 -0400	[thread overview]
Message-ID: <cover.1790795726.git.f3nr1l@me.com> (raw)

Two teardown bugs in hid-winwing, both present in mainline. The series is
based on hid.git for-next, which already carries the related fix
a1a5ad37e50c ("HID: winwing: fix use-after-free in force feedback
teardown"); it does not depend on it.

Patch 1 fixes a use-after-free of the rumble work item. winwing_remove()
cancels the work before it stops the device, but stopping the device flushes
the force feedback effects, which calls the driver's play_effect handler one
last time and queues the work again:

  hid_hw_stop() -> input_unregister_device() -> evdev_cleanup()
    -> input_flush_device() -> input_ff_flush() -> erase_effect()
    -> ml_ff_playback(dev, id, 0) -> ml_play_effects()
    -> winwing_play_effect() -> schedule_work(&data->rumble_work)

The data the work runs on is devm-allocated, and hid_device_remove() releases
the driver's devres group as soon as .remove returns, so the requeued work
runs on freed memory. Cancelling after hid_hw_stop() closes the window: once
the input device is gone nothing can queue the work again, and the driver
data is still valid until .remove returns.

Patch 2 initialises data->lights_lock, which winwing_led_write() has been
taking since the driver was merged. The mutex only ever gets the zeroing from
devm_kzalloc(); CONFIG_DEBUG_MUTEXES and lockdep both flag it on the first
brightness write.

Patch 1 needs a device with a rumble motor to trigger; patch 2 affects every
supported device. Both were pointed out by the automated Sashiko review of
the earlier force feedback fix on linux-input, and confirmed by reading the
teardown path rather than by a crash. I have since exercised patch 1 on URSA MINOR sticks, with the URSA
MINOR series (posted separately, on top of this one) applied: unloading the
module while a 5 s rumble effect is playing. ftrace shows the chain above
taking place inside hid_hw_stop(), and the requeued work running before
winwing_remove() returns; no warning or oops (on a kernel without KASAN).

A third, related issue is deliberately left out of this series. The LED class
devices are registered with devm_led_classdev_register(), so they outlive
hid_hw_stop() by the length of the devres pass that hid_device_remove() runs
after .remove returns. A sysfs brightness write in that window reaches
hid_hw_output_report() on a stopped device; usbhid returns an error once its
output URB pointer has been cleared, but that check is not serialised against
usbhid_stop(). Fixing it inside the driver means dropping devm for the LEDs
and unwinding them by hand in the probe error paths - a fair amount of churn
for a narrow race, and the same shape exists in other HID drivers that
register LEDs with devm, so it may belong in the HID core instead. I have a
driver-side patch ready and will post it separately if you prefer that.

René Onier (2):
  HID: winwing: fix use-after-free of the rumble work
  HID: winwing: initialize the lights_lock mutex

 drivers/hid/hid-winwing.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)


base-commit: 145c2b2e9a5c0f794fb4009bcb072ab19f8ccfcd
-- 
2.55.0


WARNING: multiple messages have this Message-ID
From: "René Onier" <f3nr1l@me.com>
To: Benjamin Tissoires <bentiss@kernel.org>, Jiri Kosina <jikos@kernel.org>
Cc: "René Onier" <f3nr1l@me.com>,
	"Ivan Gorinov" <linux-kernel@altimeter.info>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 0/4] HID: winwing: add WinWing URSA MINOR sticks
Date: Wed, 30 Sep 2026 15:55:56 -0400	[thread overview]
Message-ID: <cover.1790795726.git.f3nr1l@me.com> (raw)
Message-ID: <20260930195556.VEMpi3_uDKcgV1u8y1_8nGK7olT8akasdy-uXFuDO_g@z> (raw)

This series adds support for the WinWing URSA MINOR joysticks (a pair of
single-hand sticks) to hid-winwing, on top of the existing Orion 2 throttle
support.

The URSA MINOR sticks differ from the Orion 2 in three ways the series
addresses:

  - they drive a single backlight LED through the stick base (a second HID
    controller on the same endpoint, addressed by a fixed device id), not
    through the Orion 2 lighting controller;
  - they carry a single rumble motor in the grip, rather than the two
    motors of the Orion 2 grips;
  - they enumerate under their own product ids.

Patches 1 and 2 are preparatory refactors with no functional change (verified
byte-for-byte): patch 1 factors the vendor report builder out of the LED and
rumble paths and names the report fields, patch 2 makes the LED set and the
lighting controller model-dependent. Patch 3 adds the device ids and the
backlight. Patch 4 drives the single grip motor while leaving the Orion 2
two-motor path untouched.

This supersedes my earlier "HID: winwing: add support for URSA MINOR combat
joysticks", sent from my gmail address, which Jiri asked me to resend with
full paths:
https://lore.kernel.org/linux-input/20260404172641.195619-1-rene.onier@gmail.com/
The device ids and the extended button mapping it enabled are in patch 3,
now together with the backlight and the rumble motor.

The series is based on hid.git for-next and applies on top of the two-patch
series "HID: winwing: two teardown fixes":
https://lore.kernel.org/linux-input/cover.1790795726.git.f3nr1l@me.com/
The only interaction is one line of context in winwing_probe(). for-next
already carries a1a5ad37e50c ("HID: winwing: fix use-after-free in force
feedback teardown"), which the new ids need since they take the
force-feedback path.

The Fighter and Space URSA MINOR variants are electrically identical and share
these product ids; only a stick-tilt accessory differs. The Civil variant, with
fewer buttons, is likely compatible but its ids have not been verified on
hardware, so it is left out.

Tested on URSA MINOR hardware (a Space left and a Fighter right): backlight,
rumble and buttons, and unloading the module while a rumble effect plays.
I could not test the Orion 2 path myself; the two-motor rumble is unchanged
and its reports are byte-identical to before (verified), but a Tested-by on
Orion 2 would be welcome.

The vendor command names used here (SET_LEDX and the report layout) were
recovered from the vendor software's own debug logs and the command table in
its WWTHID.dll, so the report fields can be named rather than left as magic
numbers.

René Onier (4):
  HID: winwing: factor out vendor SET_LEDX report builder
  HID: winwing: make the LED set and lighting controller model-dependent
  HID: winwing: add URSA MINOR sticks
  HID: winwing: drive the URSA MINOR rumble motor

 drivers/hid/hid-winwing.c | 267 ++++++++++++++++++++++++++------------
 1 file changed, 185 insertions(+), 82 deletions(-)


base-commit: 145c2b2e9a5c0f794fb4009bcb072ab19f8ccfcd
prerequisite-patch-id: d1a20c8f9775ea37cf424f0c7026816fbfecd127
prerequisite-patch-id: e6427bc64a0650061572e3923ea44827dbd63809
-- 
2.55.0


             reply	other threads:[~2026-09-30 19:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 19:37 René Onier [this message]
2026-09-30 19:37 ` [PATCH 1/2] HID: winwing: fix use-after-free of the rumble work René Onier
2026-09-30 19:37 ` [PATCH 2/2] HID: winwing: initialize the lights_lock mutex René Onier
2026-09-30 19:55 ` [PATCH 0/4] HID: winwing: add WinWing URSA MINOR sticks René Onier
2026-09-30 19:55 ` [PATCH 1/4] HID: winwing: factor out vendor SET_LEDX report builder René Onier
2026-09-30 19:55 ` [PATCH 2/4] HID: winwing: make the LED set and lighting controller model-dependent René Onier
2026-09-30 19:55 ` [PATCH 3/4] HID: winwing: add URSA MINOR sticks René Onier
2026-09-30 19:56 ` [PATCH 4/4] HID: winwing: drive the URSA MINOR rumble motor René Onier
2026-09-30 19:58 ` [PATCH 0/2] HID: winwing: two teardown fixes René Onier

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=cover.1790795726.git.f3nr1l@me.com \
    --to=f3nr1l@me.com \
    --cc=bentiss@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@altimeter.info \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®