Re: [PATCH RFC v3 10/11] platform/x86: ideapad-laptop: Serialize keyboard backlight notifications

Ilpo Järvinen <[email protected]> Tue, 21 Jul 2026 20:09:48 +0300 (EEST)
Newsgroups dev.linux.lists.chrome-platform,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-leds,org.kernel.vger.netdev,org.kernel.vger.platform-driver-x86
Message-ID <[email protected]>
On Sun, 19 Jul 2026, Rong Zhang wrote:

> 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 notifications to
> prevent potential race conditions.
> 
> Signed-off-by: Rong Zhang <[email protected]>
> ---
>  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 5aa2fedb8472..66e16abda5e3 100644
> --- a/drivers/platform/x86/lenovo/ideapad-laptop.c
> +++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
> @@ -26,7 +26,9 @@
>  #include <linux/jiffies.h>
>  #include <linux/kernel.h>
>  #include <linux/leds.h>
> +#include <linux/lockdep.h>

Why is this being added?

>  #include <linux/module.h>
> +#include <linux/mutex.h>
>  #include <linux/platform_device.h>
>  #include <linux/platform_profile.h>
>  #include <linux/power_supply.h>
> @@ -228,6 +230,8 @@ struct ideapad_private {
>  		int type;
>  		struct led_classdev led;
>  		atomic_t last_hw_brightness;
> +
> +		struct mutex notif_mutex; /* protects notifications */
>  	} kbd_bl;
>  	struct {
>  		bool initialized;
> @@ -1720,6 +1724,8 @@ static void ideapad_kbd_bl_notify(struct ideapad_private *priv)
>  	if (!priv->kbd_bl.initialized)
>  		return;
>  
> +	guard(mutex)(&priv->kbd_bl.notif_mutex);
> +
>  	hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
>  	if (hw_brightness < 0)
>  		return;
> @@ -1745,6 +1751,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.notif_mutex);
> +	if (err)
> +		return err;
> +
>  	hw_brightness = ideapad_kbd_bl_hw_brightness_get(priv);
>  	if (hw_brightness < 0)
>  		return hw_brightness;
> 
> 

-- 
 i.