summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-05-21 18:42:41 +0200
committerLee Jones <lee@kernel.org>2026-06-17 11:29:42 +0100
commitb819dc7d8fb2896b07e51eba0381d61daf35edd7 (patch)
treed1bd69ed79228d894849a8c7a39492956b23d036
parent8f040b5c5e3a4fa6e14ec44219d4717f66923e16 (diff)
leds: core: Report ENODATA for brightness of hardware controlled LED
While the LED is controlled fully by the hardware, the value cached by the LED driver core is incorrect. Return ENODATA to userspace in this case. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260521-cros_ec-leds-hw-trigger-brightness-v1-1-6cd9d7c9671e@weissschuh.net Signed-off-by: Lee Jones <lee@kernel.org>
-rw-r--r--drivers/leds/led-class.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index a17db3d6644f..a51b0ed53886 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -27,12 +27,25 @@ static LIST_HEAD(leds_lookup_list);
static struct workqueue_struct *leds_wq;
+static bool led_trigger_is_hw_controlled(struct led_classdev *led_cdev)
+{
+#ifdef CONFIG_LEDS_TRIGGERS
+ guard(rwsem_read)(&led_cdev->trigger_lock);
+ return led_cdev->trigger && led_cdev->trigger->trigger_type;
+#else
+ return false;
+#endif
+}
+
static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
unsigned int brightness;
+ 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;