From 6887f40dadb5a263de1d9e4b5517400c08089d35 Mon Sep 17 00:00:00 2001 From: Rong Zhang Date: Mon, 21 Sep 2026 03:40:15 +0800 Subject: [PATCH] leds: class: Always protect brightness_show() with led_access The led_classdev_register_ext() protects transient states when registering with the led_access mutex and relies on all sensitive sysfs attribute callbacks holding the mutex to prevent exposing transient states. The Fixes: commit broke this as it accessed trigger_lock without holding led_access. Fix it by protecting brightness_show() with led_access in all code paths. Fixes: b819dc7d8fb2 ("leds: core: Report ENODATA for brightness of hardware controlled LED") Signed-off-by: Rong Zhang Link: https://patch.msgid.link/20260921-leds-trigger-hw-changed-v7-1-fe3cdb6dec51@rong.moe Signed-off-by: Lee Jones --- drivers/leds/led-class.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index a51b0ed53886..4259533dafa1 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -43,13 +43,13 @@ static ssize_t brightness_show(struct device *dev, struct led_classdev *led_cdev = dev_get_drvdata(dev); unsigned int brightness; - if (led_trigger_is_hw_controlled(led_cdev)) - return -ENODATA; + scoped_guard(mutex, &led_cdev->led_access) { + if (led_trigger_is_hw_controlled(led_cdev)) + return -ENODATA; - mutex_lock(&led_cdev->led_access); - led_update_brightness(led_cdev); - brightness = led_cdev->brightness; - mutex_unlock(&led_cdev->led_access); + led_update_brightness(led_cdev); + brightness = led_cdev->brightness; + } return sysfs_emit(buf, "%u\n", brightness); }