[PATCH v8 1/3] platform/x86: ideapad-laptop: Serialize keyboard backlight tracking
From: Rong Zhang
Date: Tue Nov 10 2026 - 11:01:02 EST
ACPI notifications are delivered in dedicated work contexts and may
arrive simultaneously. In the following change, much work will be done
while handling the notification, which could lead to potential race
conditions.
Introduce a new mutex to serialize keyboard backlight tracking to
prevent potential race conditions.
Acked-by: Ike Panhc <ikepanhc@xxxxxxxxx>
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
Changes in v6:
- Protects ideapad_kbd_bl_led_cdev_brightness_set() as well
Changes in v4:
- Remove needless #include (Thanks Ilpo Järvinen)
---
drivers/platform/x86/lenovo/ideapad-laptop.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index 91a8d11c79c5..04343e9a2d47 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -26,6 +26,7 @@
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/platform_profile.h>
#include <linux/power_supply.h>
@@ -204,6 +205,7 @@ struct ideapad_private {
int type;
struct led_classdev led;
unsigned int last_brightness;
+ struct mutex mutex; /* protects brightness tracking */
} kbd_bl;
struct {
bool initialized;
@@ -1663,6 +1665,8 @@ static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, unsigned
unsigned long value;
int type = priv->kbd_bl.type;
+ guard(mutex)(&priv->kbd_bl.mutex);
+
if (ideapad_kbd_bl_check_tristate(type)) {
if (brightness > priv->kbd_bl.led.max_brightness)
return -EINVAL;
@@ -1698,6 +1702,8 @@ static void ideapad_kbd_bl_notify(struct ideapad_private *priv)
if (!priv->kbd_bl.initialized)
return;
+ guard(mutex)(&priv->kbd_bl.mutex);
+
brightness = ideapad_kbd_bl_brightness_get(priv);
if (brightness < 0)
return;
@@ -1720,6 +1726,10 @@ static int ideapad_kbd_bl_init(struct ideapad_private *priv)
if (WARN_ON(priv->kbd_bl.initialized))
return -EEXIST;
+ err = devm_mutex_init(&priv->platform_device->dev, &priv->kbd_bl.mutex);
+ if (err)
+ return err;
+
if (ideapad_kbd_bl_check_tristate(priv->kbd_bl.type))
priv->kbd_bl.led.max_brightness = 2;
else
--
2.55.0