Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: led-triggers: Improvements for default trigger

Accept "default" written to sysfs trigger attr.
If the text "default" is written to the LED's sysfs 'trigger' attr, then
call led_trigger_set_default() to set the LED to its default trigger.

If the default trigger is set to "none", then led_trigger_set_default()
will remove a trigger. This is in contrast to the default trigger being
unset, in which case led_trigger_set_default() does nothing.

Signed-off-by: Craig McQueen <craig@mcqueen.au>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Link: https://lore.kernel.org/r/20250317022630.424015-1-craig@mcqueen.au
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Craig McQueen and committed by
Lee Jones
06d99fcf 08ca89e9

+19
+6
Documentation/ABI/testing/sysfs-class-led
··· 72 72 /sys/class/leds/<led> once a given trigger is selected. For 73 73 their documentation see `sysfs-class-led-trigger-*`. 74 74 75 + Writing "none" removes the trigger for this LED. 76 + 77 + Writing "default" sets the trigger to the LED's default trigger 78 + (which would often be configured in the device tree for the 79 + hardware). 80 + 75 81 What: /sys/class/leds/<led>/inverted 76 82 Date: January 2011 77 83 KernelVersion: 2.6.38
+13
drivers/leds/led-triggers.c
··· 54 54 goto unlock; 55 55 } 56 56 57 + if (sysfs_streq(buf, "default")) { 58 + led_trigger_set_default(led_cdev); 59 + goto unlock; 60 + } 61 + 57 62 down_read(&triggers_list_lock); 58 63 list_for_each_entry(trig, &trigger_list, next_trig) { 59 64 if (sysfs_streq(buf, trig->name) && trigger_relevant(led_cdev, trig)) { ··· 102 97 struct led_trigger *trig; 103 98 int len = led_trigger_snprintf(buf, size, "%s", 104 99 led_cdev->trigger ? "none" : "[none]"); 100 + 101 + if (led_cdev->default_trigger) 102 + len += led_trigger_snprintf(buf + len, size - len, " default"); 105 103 106 104 list_for_each_entry(trig, &trigger_list, next_trig) { 107 105 bool hit; ··· 288 280 289 281 if (!led_cdev->default_trigger) 290 282 return; 283 + 284 + if (!strcmp(led_cdev->default_trigger, "none")) { 285 + led_trigger_remove(led_cdev); 286 + return; 287 + } 291 288 292 289 down_read(&triggers_list_lock); 293 290 down_write(&led_cdev->trigger_lock);