Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2 0/2] platform/asus: asus-wmi: fix and unify keyboard brightness key handling
@ 2026-11-20 23:42 Bartu Alev
  2026-11-20 23:42 ` [PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates Bartu Alev
  0 siblings, 1 reply; 3+ messages in thread
From: Bartu Alev @ 2026-11-20 23:42 UTC (permalink / raw)
  To: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
	Ilpo Järvinen, Antheas Kapenekakis, Benjamin Tissoires
  Cc: Alex Bogusta, Denis Benato, platform-driver-x86, linux-kernel,
	Bartu Alev, stable

The WMI hotkey path and the HID event path in asus-wmi step the
keyboard backlight with two separate copies of the same arithmetic, and
the two copies disagree. The WMI copy computes the step in the unsigned
enum led_brightness and stores the new level without clamping it, so
holding brightness-down at zero drives the cached level negative, the
"value >= 0" apply check then drops every following transition, and the
hardware-changed notification hands the wrapped negative to userspace as
4294967294+ (or -ENODATA for -1). Pressing brightness-up at maximum
reports 4, above max_brightness.

The first patch fixes the signedness, bounds clamping, and notification
snapshot on its own so -stable trees can pick it up without the rest of
the series. The second patch removes the duplication: both paths now
step through one shared helper that reads, computes, and writes the
level inside a single hold of asus_ref.lock.

With the series applied, the level stays within
[0, ASUS_EV_MAX_BRIGHTNESS] on every transition and userspace sees no
wrapped or out-of-range values.

Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
Changes in v2:
- Rebase onto review-ilpo-next, where the driver moved to
  drivers/platform/asus/asus-wmi.c, and update subject prefixes to
  'platform/asus:'.
- Patch 1: Fix Fixes: tag to fac55d29581f ("platform/x86: asus-wmi:
  Add support for multiple kbd led handlers") and reference Alex
  Bogusta's earlier patch [1].
- Patch 1: Step in signed int instead of unsigned enum led_brightness
  and add an explanatory comment; prevents 0 - 1 from wrapping and
  clamping to max brightness (3) if patch 1 is applied standalone on
  -stable.
- Patch 1: Clear kbd_led_notify atomically when snapshotting it at the
  top of kbd_led_update_all() instead of after do_kbd_led_set().
- Patch 2: Drop inline from asus_kbd_led_calc_next(), drop the
  unreachable default case (all enum values are covered), drop the
  redundant NULL check in void asus_kbd_led_step(), and normalize an
  unknown (-1) starting level to 0 before stepping.
- Link to v1: https://patch.msgid.link/20261025-b4-asus-kbd-fixes-v1-0-fa4dcf7d2a69@gmail.com

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

---
Bartu Alev (2):
      platform/asus: asus-wmi: clamp keyboard brightness hotkey updates
      platform/asus: asus-wmi: unify WMI and HID keyboard brightness stepping

 drivers/platform/asus/asus-wmi.c | 77 +++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 41 deletions(-)
---
base-commit: 2268d837dea13a78639fa3dad60472bb67478709
change-id: 20261025-b4-asus-kbd-fixes-6c7e3780597b

Best regards,
--  
Bartu Alev <bartualev@gmail.com>


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

* [PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates
  2026-11-20 23:42 [PATCH v2 0/2] platform/asus: asus-wmi: fix and unify keyboard brightness key handling Bartu Alev
@ 2026-11-20 23:42 ` Bartu Alev
  2026-11-25 22:21   ` Ilpo Järvinen
  0 siblings, 1 reply; 3+ messages in thread
From: Bartu Alev @ 2026-11-20 23:42 UTC (permalink / raw)
  To: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
	Ilpo Järvinen, Antheas Kapenekakis, Benjamin Tissoires
  Cc: Alex Bogusta, Denis Benato, platform-driver-x86, linux-kernel,
	Bartu Alev, stable

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@bogusta.com/

Fixes: fac55d29581f ("platform/x86: asus-wmi: Add support for multiple kbd led handlers")
Cc: stable@vger.kernel.org
Cc: Antheas Kapenekakis <lkml@antheas.dev>
Cc: Alex Bogusta <alex@bogusta.com>
Cc: Denis Benato <denis.benato@linux.dev>
Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
 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


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

* Re: [PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates
  2026-11-20 23:42 ` [PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates Bartu Alev
@ 2026-11-25 22:21   ` Ilpo Järvinen
  0 siblings, 0 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2026-11-25 22:21 UTC (permalink / raw)
  To: Bartu Alev
  Cc: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
	Antheas Kapenekakis, Benjamin Tissoires, Alex Bogusta,
	Denis Benato, platform-driver-x86, LKML, stable

[-- Attachment #1: Type: text/plain, Size: 4039 bytes --]

On Sat, 21 Nov 2026, Bartu Alev wrote:

> 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()."

Yeah, and that's why you should have made a separate patch for the other 
thing. Don't mix logically separate changes into a single change.

...Also, Alex's patch is already applied.

-- 
 i.

> [1] https://lore.kernel.org/r/20261016015117.32174-1-alex@bogusta.com/
> 
> Fixes: fac55d29581f ("platform/x86: asus-wmi: Add support for multiple kbd led handlers")
> Cc: stable@vger.kernel.org
> Cc: Antheas Kapenekakis <lkml@antheas.dev>
> Cc: Alex Bogusta <alex@bogusta.com>
> Cc: Denis Benato <denis.benato@linux.dev>
> Signed-off-by: Bartu Alev <bartualev@gmail.com>
> ---
>  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;
>  
> 
> 

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

end of thread, other threads:[~2026-11-25 22:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 23:42 [PATCH v2 0/2] platform/asus: asus-wmi: fix and unify keyboard brightness key handling Bartu Alev
2026-11-20 23:42 ` [PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates Bartu Alev
2026-11-25 22:21   ` Ilpo Järvinen

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