From: sashiko-bot@kernel.org
To: "Rong Zhang" <i@rong.moe>
Cc: lee@kernel.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH v5 12/12] platform/x86: ideapad-laptop: Fully support auto keyboard backlight
Date: Fri, 21 Aug 2026 17:27:42 +0000 [thread overview]
Message-ID: <20260821172742.F3FB31F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260821-leds-trigger-hw-changed-v5-12-3e00d6c4a936@rong.moe>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Hardware brightness state falls out of sync with `last_hw_brightness` due to a TOCTOU race between ACPI notify and sysfs write.
--
--- Patch [12]: [PATCH v5 12/12] platform/x86: ideapad-laptop: Fully support auto keyboard backlight ---
commit 775eb668f48ee8e4ee7f513342cb65f613086809
Author: Rong Zhang <i@rong.moe>
platform/x86: ideapad-laptop: Fully support auto keyboard backlight
This commit adds support for the auto brightness mode of the keyboard
backlight on IdeaPad laptops. It introduces a private hardware control
trigger to handle the auto mode and blocks brightness changes on exit
to retain state across boots.
> diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
> index 7f7b1e30c3263..5442cbfe3969b 100644
> --- a/drivers/platform/x86/lenovo/ideapad-laptop.c
> +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
[ ... ]
> @@ -1739,6 +1790,8 @@ static void ideapad_kbd_bl_notify(struct ideapad_private *priv)
> if (hw_brightness == last_hw_brightness)
> return;
>
> + ideapad_kbd_bl_notify_hw_control(priv, hw_brightness, last_hw_brightness);
> +
[Severity: Medium]
Can a race condition here cause the hardware brightness state to permanently
fall out of sync with the internal tracker?
Looking at ideapad_kbd_bl_notify(), it reads the current hardware brightness
and then updates the tracker using atomic_xchg():
ideapad_kbd_bl_notify() {
...
hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
...
last_hw_brightness = atomic_xchg(&priv->kbd_bl.last_hw_brightness, hw_brightness);
}
If a concurrent sysfs write triggers ideapad_kbd_bl_hw_brightness_set()
in the middle of this process, could we see this sequence:
Thread 1 (ideapad_kbd_bl_notify):
Reads hw_brightness (e.g., 1)
Thread 2 (sysfs write):
Calls ideapad_kbd_bl_hw_brightness_set()
Sets actual hardware brightness to 3 (auto mode)
Calls atomic_set(&priv->kbd_bl.last_hw_brightness, 3)
Thread 1 (ideapad_kbd_bl_notify resumes):
Calls atomic_xchg(&priv->kbd_bl.last_hw_brightness, 1)
Wouldn't Thread 1 blindly overwrite the correct atomic state (3) with the
stale read state (1)?
This seems like it would permanently desync the last_hw_brightness tracker
from the actual hardware, breaking ideapad_kbd_bl_auto_trigger_offloaded()
which would now falsely report that the trigger is not offloaded.
> led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260821-leds-trigger-hw-changed-v5-0-3e00d6c4a936@rong.moe?part=12
next prev parent reply other threads:[~2026-08-21 17:27 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 17:21 [PATCH v5 00/12] leds: Add support for hardware-initiated hardware control trigger transition Rong Zhang
2026-08-20 17:21 ` [PATCH v5 01/12] leds: Move led_trigger_is_hw_controlled() to the right place Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-20 17:21 ` [PATCH v5 02/12] leds: class: Remove hardware control trigger when writing brightness Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-20 17:21 ` [PATCH v5 03/12] leds: trigger: Add offloaded() callback and provide trigger_may_offload attribute Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-20 17:21 ` [PATCH v5 04/12] leds: cros_ec: Implement offloaded() trigger callback Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-20 17:22 ` [PATCH v5 05/12] leds: turris-omnia: Implement offloaded() trigger callback and declare hw_control_trigger Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-22 18:56 ` Rong Zhang
2026-08-20 17:22 ` [PATCH v5 06/12] leds: trigger: netdev: Implement offloaded() callback Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-22 19:01 ` Rong Zhang
2026-08-20 17:22 ` [PATCH v5 07/12] leds: trigger: Enforce strict checks in led_trigger_is_hw_controlled() Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-22 19:10 ` Rong Zhang
2026-08-20 17:22 ` [PATCH v5 08/12] leds: trigger: Do not attach trigger to a removing LED Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-22 19:40 ` Rong Zhang
2026-08-20 17:22 ` [PATCH v5 09/12] leds: trigger: Add led_trigger_notify_hw_control_changed() interface Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-20 17:22 ` [PATCH v5 10/12] platform/x86: ideapad-laptop: Decouple hardware & classdev brightness for keyboard backlight Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-22 20:26 ` Rong Zhang
2026-08-20 17:22 ` [PATCH v5 11/12] platform/x86: ideapad-laptop: Serialize keyboard backlight notifications Rong Zhang
2026-08-21 17:27 ` sashiko-bot
2026-08-20 17:22 ` [PATCH v5 12/12] platform/x86: ideapad-laptop: Fully support auto keyboard backlight Rong Zhang
2026-08-21 17:27 ` sashiko-bot [this message]
2026-08-22 20:25 ` Rong Zhang
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=20260821172742.F3FB31F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=i@rong.moe \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.