[PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates

From: Bartu Alev

Date: Fri Nov 20 2026 - 18:42:52 EST


The NOTIFY_KBD_BRTUP/DWN/TOGGLE handlers pass led_value ± 1 into
kbd_led_set_by_kbd(), which stores the value into asus->kbd_led_wk
without clamping it. Pressing brightness-down at level 0 drives the
cached level negative (-1, -2, ...); kbd_led_update_all() then drops
every hardware update on its "value >= 0" check while
led_classdev_notify_brightness_hw_changed() hands the wrapped negative
to userspace, so brightness_hw_changed reports 4294967294+ or ENODATA
and the brightness-up key appears dead until the counter climbs back
to 0. Pressing brightness-up at maximum reports 4, above
max_brightness.

Compute the level as int and clamp it in kbd_led_set_by_kbd(): the
stepping must happen in a signed type, because enum led_brightness is
an unsigned type in practice and 0 - 1 passed through it wraps to a
value that clamps to full brightness instead of staying off.

Also clear kbd_led_notify when snapshotting it in
kbd_led_update_all() instead of after updating the hardware, so a
keypress queued while the worker runs is not swallowed by the late
clear.

This addresses the same bug as Alex Bogusta's earlier patch
(reviewed by Denis Benato) [1], while also closing the kbd_led_notify
race in kbd_led_update_all()."

[1] https://lore.kernel.org/r/20261016015117.32174-1-alex@xxxxxxxxxxx/

Fixes: fac55d29581f ("platform/x86: asus-wmi: Add support for multiple kbd led handlers")
Cc: stable@xxxxxxxxxxxxxxx
Cc: Antheas Kapenekakis <lkml@xxxxxxxxxxx>
Cc: Alex Bogusta <alex@xxxxxxxxxxx>
Cc: Denis Benato <denis.benato@xxxxxxxxx>
Signed-off-by: Bartu Alev <bartualev@xxxxxxxxx>
---
drivers/platform/asus/asus-wmi.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
index b33ebdb21aa2..f1a94bcdb0c0 100644
--- a/drivers/platform/asus/asus-wmi.c
+++ b/drivers/platform/asus/asus-wmi.c
@@ -1784,6 +1784,7 @@ static void kbd_led_update_all(struct work_struct *work)
registered = asus->kbd_led_registered;
value = asus->kbd_led_wk;
notify = asus->kbd_led_notify;
+ asus->kbd_led_notify = false;
}

if (!registered) {
@@ -1806,11 +1807,8 @@ static void kbd_led_update_all(struct work_struct *work)

if (value >= 0)
do_kbd_led_set(&asus->kbd_led, value);
- if (notify) {
- scoped_guard(spinlock_irqsave, &asus_ref.lock)
- asus->kbd_led_notify = false;
+ if (notify)
led_classdev_notify_brightness_hw_changed(&asus->kbd_led, value);
- }
}

/*
@@ -1958,10 +1956,16 @@ static int kbd_led_set(struct led_classdev *led_cdev, enum led_brightness value)
return 0;
}

-static void kbd_led_set_by_kbd(struct asus_wmi *asus, enum led_brightness value)
+static void kbd_led_set_by_kbd(struct asus_wmi *asus, int value)
{
+ /*
+ * The hotkey callers step the level by one, which must happen in
+ * a signed type: enum led_brightness is an unsigned type in
+ * practice, so -1 passed through it wraps to a value that clamps
+ * to ASUS_EV_MAX_BRIGHTNESS instead of staying off.
+ */
scoped_guard(spinlock_irqsave, &asus_ref.lock) {
- asus->kbd_led_wk = value;
+ asus->kbd_led_wk = clamp_val(value, 0, ASUS_EV_MAX_BRIGHTNESS);
asus->kbd_led_notify = true;
}
queue_work(asus->led_workqueue, &asus->kbd_led_work);
@@ -4677,7 +4681,7 @@ static int asus_wmi_get_event_code(union acpi_object *obj)

static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
{
- enum led_brightness led_value;
+ int led_value;
unsigned int key_value = 1;
bool autorelease = 1;


--
2.56.1