mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] platform/x86: lg-laptop: Fix possible LED deadlock
@ 2026-11-21 14:12 Armin Wolf
  2026-11-21 14:12 ` [PATCH 2/2] platform/x86: lg-laptop: Improve keyboard backlight detection Armin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Armin Wolf @ 2026-11-21 14:12 UTC (permalink / raw)
  To: matan; +Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel, daxter1992

Calling ACPI control methods inside the .brightness_set callback
of a LED class device can cause deadlocks because this callback
must not sleep. Use .brightness_set_blocking instead.

Fixes: dbf0c5a6b1f8 ("platform/x86: Add LG Gram laptop special features driver")
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/lg-laptop.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index 36ad1e269443..a784071de8b3 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -32,7 +32,7 @@
 #define LED_DEVICE(_name, max, flag) struct led_classdev _name = { \
 	.name           = __stringify(_name),   \
 	.max_brightness = max,                  \
-	.brightness_set = _name##_set,          \
+	.brightness_set_blocking = _name##_set, \
 	.brightness_get = _name##_get,          \
 	.flags = flag,                          \
 }
@@ -599,10 +599,9 @@ static const struct attribute_group dev_attribute_group = {
 	.attrs = dev_attributes,
 };
 
-static void tpad_led_set(struct led_classdev *cdev,
-			 enum led_brightness brightness)
+static int tpad_led_set(struct led_classdev *cdev, enum led_brightness brightness)
 {
-	lg_wmab_set(cdev->dev->parent, WM_TLED, brightness > LED_OFF);
+	return lg_wmab_set(cdev->dev->parent, WM_TLED, brightness > LED_OFF);
 }
 
 static enum led_brightness tpad_led_get(struct led_classdev *cdev)
@@ -612,8 +611,7 @@ static enum led_brightness tpad_led_get(struct led_classdev *cdev)
 
 static LED_DEVICE(tpad_led, 1, 0);
 
-static void kbd_backlight_set(struct led_classdev *cdev,
-			      enum led_brightness brightness)
+static int kbd_backlight_set(struct led_classdev *cdev, enum led_brightness brightness)
 {
 	/* Must always be written */
 	u32 value = KBD_LED_STATUS;
@@ -633,7 +631,7 @@ static void kbd_backlight_set(struct led_classdev *cdev,
 	value |= FIELD_PREP(KBD_LED_BRIGHTNESS_MASK, bright);
 	value |= FIELD_PREP(KBD_LED_MODE_MASK, mode);
 
-	lg_wmab_set(cdev->dev->parent, WM_KEY_LIGHT, value);
+	return lg_wmab_set(cdev->dev->parent, WM_KEY_LIGHT, value);
 }
 
 static enum led_brightness get_kbd_backlight_level(struct device *dev)
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] platform/x86: lg-laptop: Improve keyboard backlight detection
  2026-11-21 14:12 [PATCH 1/2] platform/x86: lg-laptop: Fix possible LED deadlock Armin Wolf
@ 2026-11-21 14:12 ` Armin Wolf
  0 siblings, 0 replies; 2+ messages in thread
From: Armin Wolf @ 2026-11-21 14:12 UTC (permalink / raw)
  To: matan; +Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel, daxter1992

Not all devices support the keyboard backlight feature, instead they
will return an error when trying to read/write the backlight level.

Avoid registering the associated LED class device on such devices
by first verifying that reading of the backlight level works. For
this the get_kbd_backlight_level() function has to be modified to
stop hiding any errors coming from the WMAB call.

Reported-by: Carlos Javier Alvarez <daxter1992@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222275
Tested-by: Carlos Javier Alvarez <daxter1992@gmail.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/lg-laptop.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index a784071de8b3..72955fc868af 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -641,10 +641,10 @@ static enum led_brightness get_kbd_backlight_level(struct device *dev)
 
 	ret = lg_wmab_get(dev, WM_KEY_LIGHT, &value);
 	if (ret < 0)
-		return LED_OFF;
+		return ret;
 
 	if (FIELD_GET(KBD_LED_MAGIC_MASK, value) != KBD_LED_MAGIC)
-		return LED_OFF;
+		return -EIO;
 
 	if (FIELD_GET(KBD_LED_MODE_MASK, value) == KBD_LED_MODE_OFF)
 		return LED_OFF;
@@ -823,6 +823,21 @@ static int lg_laptop_input_init(struct device *dev, acpi_handle handle)
 	return 0;
 }
 
+static int lg_laptop_kbd_backlight_init(struct device *dev)
+{
+	int ret;
+
+	/*
+	 * Devices that do not support the keyboard backlight feature
+	 * usually return a error when trying to read the backlight level.
+	 */
+	ret = get_kbd_backlight_level(dev);
+	if (ret < 0)
+		return ret;
+
+	return devm_led_classdev_register(dev, &kbd_backlight);
+}
+
 static acpi_status lg_laptop_address_space_write(struct device *dev, acpi_physical_address address,
 						 size_t size, u64 value)
 {
@@ -1035,7 +1050,7 @@ static int acpi_probe(struct platform_device *pdev)
 		battery_limit_use_wmbb = 1;
 
 	/* LEDs are optional */
-	ret = devm_led_classdev_register(&pdev->dev, &kbd_backlight);
+	ret = lg_laptop_kbd_backlight_init(&pdev->dev);
 	if (ret < 0)
 		kbd_backlight_available = false;
 	else
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-21 14:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 14:12 [PATCH 1/2] platform/x86: lg-laptop: Fix possible LED deadlock Armin Wolf
2026-11-21 14:12 ` [PATCH 2/2] platform/x86: lg-laptop: Improve keyboard backlight detection Armin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®