Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH v5 0/3] HID: wiimote: new LED behavior on connect + scoped_guards
@ 2026-10-09  2:27 Rafael Passos
  2026-10-09  2:27 ` [PATCH v5 1/3] HID: wiimote: turn on the LEDs indicating the controller id Rafael Passos
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Rafael Passos @ 2026-10-09  2:27 UTC (permalink / raw)
  To: David Rheinsberg, bentiss, jikos
  Cc: Shuah Khan, Brigham Campbell, Jori Koolstra, Rafael Passos,
	linux-input

Hi,
This patchset contains one feature change, and 3 patches appying 
scoped cleanup to locking and to the initialization functions for
the led probing and the main wiimote probe call.

The feature is turning different LEDs for each of the first 4 wiimotes connected.
From id 5 forward, the LED will cycle back to 1, and so on.
This uses the ida struct, so its quite simple and lightweight.
The hid_info log message prints out the controller id.

While implementing this feature, I decided to cleanup the code using
scoped_guard for the many spinlocks in the driver. There are two places
where the original lock/unlock version fits best, and I left them
untouched.
I also used the __free scope cleanup in the wiimote_probe and LED probe.

It was really fun working with this driver.
I tested it with 4 Wii Motion Plus remotes (gen2).
Video recording of my tests (48s video).
https://rcpassos.me/video/wiimote-led-linux-driver

Thanks,
Rafael Passos

---
V1: https://lore.kernel.org/linux-input/20260710153456.2093889-1-rafael@rcpassos.me/
Changes from v1:
    (1/3):
    - fix ida_alloc_min error handling to consider negative values
    - remove fallback to 1 on ida_alloc_min failure
    - move player_leds static array to hid-wiimote-core.c
    - s/instance_id/player_id/g
    - store player_id on an u8
    (2/3):
    - add header include for cleanup.h
    - add identation to one-liner scoped_guards
    (3/3):
    - add scoped cleanup function to wiimote_probe, with a bitmask to track state
      Patch used for testing this:
      https://lore.kernel.org/linux-input/20260715213513.3929001-1-rafael@rcpassos.me/
    (4/4) *new patch* :
    - sashiko found a pre-existing uaf. Unlikely, but correct.
      implemented using the playstation driver as an inspiration

V2: https://lore.kernel.org/linux-input/20260710153456.2093889-1-rafael@rcpassos.me/
Changes from v2:
    (2/4):
    - join the last two locks into a single scoped_guard lock in wiimote_modules_load

V3: https://lore.rcpassos.me/wiimote/20260729164928.1138468-1-rafael@rcpassos.me/
Changes from v3:
    - dropped false uaf patch (previous 4/4). It was a false alarm.
      Discussion in:
      https://lore.kernel.org/linux-input/20260729164928.1138468-1-rafael@rcpassos.me/T/#t

    (1/4):
    - I tested how the changes looked if using ida from 0 instead of 1,
      and I believe it ended up less clean. I decided to keep them as is,
      with a few additional comments.
    - explicit initialization of player_id to 0 before allocating an id
    - avoid using a new int during ida_alloc (use ret instead)
    - use u8 instead of __u8
    - move ida_remove from wiimote_hid_remove to wiimote_destroy
    - add debugfs entry for the player_id entry
    (3/4):
    - move changes to wiimote_probe from this patch to the next
    - update patch title
    (4/4): *new patch*
    - scoped cleanup in the wiimote_probe call, using a bitmask to keep
      track of state during initialization
    - update wiimote_destroy so it can be the cleanup function
    - add a debugfs entry for this new entry

V4: https://lore.kernel.org/linux-input/20260817213840.1053216-1-rafael@rcpassos.me/
Changes from v4:
    - dropped wiimote probe with scoped guards (previous 4/4). It was too complex.
      Maybe we can still find a simpler way, outside of this patchset.
    
    (1/3):
    - drop previous wiiproto_req_leds call from wiimod_led_probe
      (covered by the new one in wiimote_modules_load)
    - On the call to wiiproto_req_leds in wiimote_modules_load:
        - Use U1 and to avoid integer promotion rules.
        - Use ARRAY_SIZE(player_leds) to avoid the hard-coded size
        - move call into spin-lock above
    - add guard to ida_free (was places in thw wrong patch)
    - replace ida_alloc_min by ida_alloc_range
    - change hid_info "registered" log to use the wdata->player_id value
    (2/3):
    - fix some whitespace/tab indentation mixup
    (3/3):
    - split declaration and assignment in the kzalloc

Thanks!


Rafael Passos (3):
  HID: wiimote: turn on the LEDs indicating the controller id
  HID: wiimote: replace spinlock pairs with scoped_guard
  HID: wiimote: led_probe with scoped cleanup

 drivers/hid/hid-wiimote-core.c    | 277 ++++++++++++++++--------------
 drivers/hid/hid-wiimote-debug.c   |  67 ++++----
 drivers/hid/hid-wiimote-modules.c |  22 +--
 drivers/hid/hid-wiimote.h         |   1 +
 4 files changed, 183 insertions(+), 184 deletions(-)

-- 
2.55.0


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

end of thread, other threads:[~2026-10-11 12:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-09  2:27 [PATCH v5 0/3] HID: wiimote: new LED behavior on connect + scoped_guards Rafael Passos
2026-10-09  2:27 ` [PATCH v5 1/3] HID: wiimote: turn on the LEDs indicating the controller id Rafael Passos
2026-10-09  2:44   ` sashiko-bot
2026-10-09  2:28 ` [PATCH v5 2/3] HID: wiimote: replace spinlock pairs with scoped_guard Rafael Passos
2026-10-09  2:44   ` sashiko-bot
2026-10-11 12:54     ` Rafael Passos
2026-10-09  2:28 ` [PATCH v5 3/3] HID: wiimote: led_probe with scoped cleanup Rafael Passos

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