[PATCH v3 3/7] platform/x86: thinkpad_acpi: Sync LED core state on level writes

From: Qiling Zhu

Date: Sat Nov 14 2026 - 12:56:44 EST


kbdlight_set_level_and_update() pokes the led_classdev brightness cache
directly after writing the new EC level, without notifying userspace and
without any locking. Commit 06da5325d02e ("platform/x86: thinkpad_acpi:
Stop setting led_classdev brightness directly") already removed this
pattern from the sysfs path but had to keep it for the proc interface,
which has no LED core path of its own.

Move the LED core state update into kbdlight_notify_level(): stop
updating the cached level in kbdlight_set_level() and have both the
sysfs and the proc write paths go through kbdlight_set_level_and_update(),
which writes the EC level and updates the cache under kbdlight_mutex,
and reports the new level through the LED core, like commit
07f48f668fac ("platform/x86: ideapad-laptop: add FnLock LED class
device") did for the ideapad FnLock LED.

As a result, writing a level through either interface now emits a
brightness_hw_changed notification, so userspace listeners see level
changes from both of them.

Signed-off-by: Qiling Zhu <kmatzkaczor244@xxxxxxxxx>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 23 +++++++++++++--------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index c8098f317..657a19d11 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5108,17 +5108,17 @@ static struct ibm_struct video_driver_data = {
static enum led_brightness kbdlight_brightness;
static DEFINE_MUTEX(kbdlight_mutex);

+/*
+ * Caller must hold kbdlight_mutex.
+ */
static int kbdlight_set_level(int level)
{
if (!hkey_handle)
return -ENXIO;

- guard(mutex)(&kbdlight_mutex);
-
if (!acpi_evalf(hkey_handle, NULL, "MLCS", "dd", level))
return -EIO;

- kbdlight_brightness = level;
return 0;
}

@@ -5183,10 +5183,12 @@ static bool kbdlight_is_supported(void)
return status & BIT(9);
}

+static int kbdlight_set_level_and_update(int level);
+
static int kbdlight_sysfs_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
- return kbdlight_set_level(brightness);
+ return kbdlight_set_level_and_update(brightness);
}

static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
@@ -5245,18 +5247,21 @@ static void kbdlight_exit(void)
led_classdev_unregister(&tpacpi_led_kbdlight.led_classdev);
}

+static void kbdlight_notify_level(int level);
+
static int kbdlight_set_level_and_update(int level)
{
int ret;
- struct led_classdev *led_cdev;
+
+ guard(mutex)(&kbdlight_mutex);

ret = kbdlight_set_level(level);
- led_cdev = &tpacpi_led_kbdlight.led_classdev;
+ if (ret)
+ return ret;

- if (ret == 0 && !(led_cdev->flags & LED_SUSPENDED))
- led_cdev->brightness = level;
+ kbdlight_notify_level(level);

- return ret;
+ return 0;
}

static int kbdlight_read(struct seq_file *m)
--
2.56.1