[PATCH] HID: nintendo: fix lost update of player LED state
From: Lu Huang
Date: Mon Sep 28 2026 - 05:11:42 EST
The player LED subcommand programs all four LEDs with a single
value, so joycon_player_led_brightness_set() must aggregate the
current brightness of all four LEDs and send that snapshot
atomically. Commit 928276075f16 ("HID: nintendo: cleanup LED
code") moved the aggregation loop out of output_mutex: if an
update callback is preempted after reading the four states and
another update sends its own snapshot first, the preempted
callback later sends its stale value and silently reverts the
completed update, leaving the hardware LED state inconsistent
with sysfs brightness.
Move the aggregation loop back under output_mutex so reading
the four LED states and sending the subcommand are serialized.
Fixes: 928276075f16 ("HID: nintendo: cleanup LED code")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lu Huang <huanglu@xxxxxxxxxx>
---
drivers/hid/hid-nintendo.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 43e0f2aaea3b..b0d7c91490f9 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -2264,10 +2264,9 @@ static int joycon_player_led_brightness_set(struct led_classdev *led,
return -ENODEV;
}
+ mutex_lock(&ctlr->output_mutex);
for (i = 0; i < JC_NUM_LEDS; i++)
val |= ctlr->leds[i].brightness << i;
-
- mutex_lock(&ctlr->output_mutex);
ret = joycon_set_player_leds(ctlr, 0, val);
mutex_unlock(&ctlr->output_mutex);
--
2.25.1