From: sashiko-bot@kernel.org
To: "Qiling Zhu" <kmatzkaczor244@gmail.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v6 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger
Date: Thu, 03 Dec 2026 12:50:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-247790@kernel.org> (raw)
In-Reply-To: <20261203120704.41431-7-kmatzkaczor244@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] platform/x86: thinkpad_acpi: kbdlight_auto_trigger_activate()
races EC state
- [Medium] platform/x86: thinkpad_acpi: sysfs brightness write clobbered
by auto trigger
--
commit 530265d2e67f80c165f57650f253fcb8bc085f3d
Author: Qiling Zhu <kmatzkaczor244@gmail.com>
platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger
This commit exposes ThinkPad keyboard backlight auto mode (EC level 3) as a
private LED trigger named "tpacpi-kbd-auto" and wires hardware transitions to
led_trigger_notify_hw_control_changed().
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 8f73f87e929dc..af53117d554c6 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -5218,6 +5218,27 @@ static bool kbdlight_is_supported(void)
> return status & BIT(9);
> }
>
> +static struct led_hw_trigger_type kbdlight_auto_trigger_type;
> +
> +static int kbdlight_auto_trigger_activate(struct led_classdev *led_cdev)
> +{
> + return kbdlight_set_level_and_update(TPACPI_KBD_LIGHT_AUTO_LEVEL);
> +}
[Severity: Medium]
Can kbdlight_auto_trigger_activate() revert a newer hardware transition and
desynchronize the trigger from the EC?
When Fn+Space cycles rapidly past auto mode (level 2 -> 3 -> 0), the first
kbdlight_notify_level(3) queues trigger_hw_changed_work with activate = true.
__led_trigger_set() then blocks in synchronize_rcu() before calling
kbdlight_auto_trigger_activate(), opening a multi-millisecond window:
kworker ACPI notify (Fn+Space)
led_trigger_hw_control_changed_worker()
activate = true
__led_trigger_set(..., trig, true)
led_cdev->trigger = trig
synchronize_rcu()
kbdlight_notify_level(0)
led_trigger_notify_hw_control_changed(
..., false)
kbdlight_brightness = 0
kbdlight_auto_trigger_activate()
MLCS(3); kbdlight_brightness = 3 <-- reverts EC to auto mode
led_trigger_hw_control_changed_worker()
activate = false
__led_trigger_set(..., NULL, true) <-- detaches trigger, EC stays at 3
The resulting MLCS(3) EC echo is ignored by kbdlight_notify_level() because
kbdlight_brightness is already 3, and __led_trigger_set(..., NULL, true)
skips turning off the LED when hw_triggered is true. The user's second
Fn+Space press is reverted, leaving the EC and kbdlight_brightness stuck in
auto mode while sysfs trigger reports [none] and brightness reports 0 instead
of -ENODATA.
A concurrent sysfs trigger write to tpacpi-kbd-auto racing with a pending
activate = false worker can similarly detach the trigger while leaving the EC
in auto mode.
[ ... ]
> @@ -5295,6 +5349,12 @@ static void kbdlight_notify_level(int level)
> if (level == kbdlight_brightness)
> return;
>
> + was_auto = kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL;
> + is_auto = level == TPACPI_KBD_LIGHT_AUTO_LEVEL;
> +
> + if (is_auto != was_auto && led_cdev->hw_control_trigger)
> + led_trigger_notify_hw_control_changed(led_cdev, is_auto);
> +
> kbdlight_brightness = level;
> led_classdev_notify_brightness_hw_changed(led_cdev, kbdlight_level_to_brightness(level));
> }
[Severity: Medium]
What happens if userspace writes a manual brightness to sysfs after
kbdlight_notify_level(3) queues trigger_hw_changed_work (and wakes listeners
via led_classdev_notify_brightness_hw_changed()), but before the worker
attaches kbdlight_auto_trigger?
userspace (sysfs brightness) kworker
brightness_store(state)
led_cdev->trigger == NULL
led_set_brightness(..., state)
set_brightness_work:
kbdlight_sysfs_set(state)
kbdlight_set_level_and_update(state)
led_trigger_hw_control_changed_worker()
activate = true
__led_trigger_set(..., trig, true)
flush_work(&set_brightness_work)
kbdlight_auto_trigger_activate()
<-- overwrites EC back to level 3
Because led_cdev->trigger is still NULL during brightness_store(),
led_trigger_remove() / led_trigger_remove_hw_control() is a no-op and does
not clear trigger_hw_changed. kbdlight_set_level_and_update() does not call
led_trigger_notify_hw_control_changed(led_cdev, false) either, and the EC
echo is ignored because level == kbdlight_brightness.
When the worker runs, flush_work(&led_cdev->set_brightness_work) ensures the
manual write completes first, and kbdlight_auto_trigger_activate() then
silently overwrites the sysfs brightness write back to EC level 3 with
tpacpi-kbd-auto attached.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203120704.41431-1-kmatzkaczor244@gmail.com?part=6
next prev parent reply other threads:[~2026-12-03 12:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-12-03 12:06 ` [PATCH v6 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves Qiling Zhu
2026-12-03 12:50 ` sashiko-bot
2026-12-03 12:07 ` [PATCH v6 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-12-03 12:50 ` sashiko-bot [this message]
2026-12-03 12:50 ` [PATCH v6 0/6] " sashiko-bot
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=sashiko-outbox-247790@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kmatzkaczor244@gmail.com \
--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.