[PATCH v4 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers

From: Qiling Zhu

Date: Wed Nov 25 2026 - 03:48:58 EST


TP_HKEY_EV_KBD_LIGHT handling in tpacpi_driver_event() reads back the
brightness, compares it with the cached value and notifies the LED core
inline. Extract this block into two helpers: kbdlight_notify_level()
takes a brightness, compares it with the cached value, updates the cache
and notifies the LED core; kbdlight_notify_change() reads the brightness
back and calls the former under kbdlight_mutex, like the original inline
code did.

kbdlight_notify_level() expects the caller to hold kbdlight_mutex, so
that the proc write path can reuse it with the brightness it has just
written in a subsequent change.

No functional change intended.

Signed-off-by: Qiling Zhu <kmatzkaczor244@xxxxxxxxx>
Reviewed-by: Rong Zhang <i@xxxxxxxx>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 42 +++++++++++++--------
1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 31d3721bb..b4b3d7dcc 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5267,6 +5267,30 @@ static int kbdlight_set_level_and_update(int level)
return ret;
}

+static void kbdlight_notify_level(int level)
+{
+ struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+
+ lockdep_assert_held(&kbdlight_mutex);
+
+ /*
+ * Check the level actually changed, setting the level
+ * through kbdlight_set_level() also triggers this event.
+ */
+ if (level == kbdlight_brightness)
+ return;
+
+ kbdlight_brightness = level;
+ led_classdev_notify_brightness_hw_changed(led_cdev, level);
+}
+
+static void kbdlight_notify_change(void)
+{
+ guard(mutex)(&kbdlight_mutex);
+
+ kbdlight_notify_level(kbdlight_sysfs_get(NULL));
+}
+
static int kbdlight_read(struct seq_file *m)
{
int level;
@@ -11593,22 +11617,8 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
/* Key events are suppressed by default hotkey_user_mask */
return false;
case TP_HKEY_EV_KBD_LIGHT:
- if (tp_features.kbdlight) {
- enum led_brightness brightness;
-
- guard(mutex)(&kbdlight_mutex);
-
- /*
- * Check the brightness actually changed, setting the brightness
- * through kbdlight_set_level() also triggers this event.
- */
- brightness = kbdlight_sysfs_get(NULL);
- if (kbdlight_brightness != brightness) {
- kbdlight_brightness = brightness;
- led_classdev_notify_brightness_hw_changed(
- &tpacpi_led_kbdlight.led_classdev, brightness);
- }
- }
+ if (tp_features.kbdlight)
+ kbdlight_notify_change();
/* Key events are suppressed by default hotkey_user_mask */
return false;
case TP_HKEY_EV_DFR_CHANGE_ROW:
--
2.56.1