[PATCH 11/21] leds: class: Unlock led_access before unregistering device on error

From: Lee Jones

Date: Wed Oct 21 2026 - 08:43:22 EST


In led_classdev_register_ext(), if led_add_brightness_hw_changed() fails
after device_create_with_groups() has exposed the LED sysfs attributes,
calling device_unregister() while holding led_cdev->led_access can
cause an AB-BA deadlock with a concurrent sysfs access that holds an
active kernfs reference and blocks on led_cdev->led_access.

Disable sysfs writes and release led_cdev->led_access before calling
device_unregister() on the error path.

Fixes: 6d71021ab3b0 ("leds: class: ensure workqueue is initialized before setting brightness")
Closes: https://sashiko.dev/#/bug/linux-400d8d29-9e78-4fb7-af37-b07c92bdf4df
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/leds/led-class.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 2a3040fa3c4b..c8529003dbe1 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -549,9 +549,10 @@ int led_classdev_register_ext(struct device *parent,
if (led_cdev->flags & LED_BRIGHT_HW_CHANGED) {
ret = led_add_brightness_hw_changed(led_cdev);
if (ret) {
+ led_sysfs_disable(led_cdev);
+ mutex_unlock(&led_cdev->led_access);
device_unregister(led_cdev->dev);
led_cdev->dev = NULL;
- mutex_unlock(&led_cdev->led_access);
return ret;
}
}
--
2.56.0.218.g1ec904b173-goog