Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Bartu Alev <bartualev@gmail.com>
Cc: Corentin Chary <corentin.chary@gmail.com>,
	 "Luke D. Jones" <luke@ljones.dev>,
	Denis Benato <denis.benato@linux.dev>,
	 Hans de Goede <hansg@kernel.org>,
	Antheas Kapenekakis <lkml@antheas.dev>,
	 Benjamin Tissoires <bentiss@kernel.org>,
	Alex Bogusta <alex@bogusta.com>,
	 Denis Benato <benato.denis96@gmail.com>,
	 platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	 stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] platform/asus: asus-wmi: clamp keyboard brightness hotkey updates
Date: Thu, 26 Nov 2026 00:21:05 +0200 (EET)	[thread overview]
Message-ID: <2ed99bdc-21f6-6dab-8a19-25d7d5061fae@linux.intel.com> (raw)
In-Reply-To: <20261121-b4-asus-kbd-fixes-v2-1-52cda07d233f@gmail.com>

[-- 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;
>  
> 
> 

      reply	other threads:[~2026-11-25 22:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=2ed99bdc-21f6-6dab-8a19-25d7d5061fae@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=alex@bogusta.com \
    --cc=bartualev@gmail.com \
    --cc=benato.denis96@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=corentin.chary@gmail.com \
    --cc=denis.benato@linux.dev \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkml@antheas.dev \
    --cc=luke@ljones.dev \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stable@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