diff options
| author | Rong Zhang <i@rong.moe> | 2026-09-21 03:40:15 +0800 |
|---|---|---|
| committer | Lee Jones <lee@kernel.org> | 2026-09-24 13:17:32 +0100 |
| commit | 6887f40dadb5a263de1d9e4b5517400c08089d35 (patch) | |
| tree | 91b182496a726dcc3c6a18b356c2ae8cec75af72 /drivers | |
| parent | d4948551280b1d52c1896b7c80d5383b7d8ad7c5 (diff) | |
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 <i@rong.moe>
Link: https://patch.msgid.link/20260921-leds-trigger-hw-changed-v7-1-fe3cdb6dec51@rong.moe
Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/leds/led-class.c | 12 |
1 files 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); } |
