summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2023-12-22 01:19:17 +0300
committerLee Jones <lee@kernel.org>2024-03-07 11:47:55 +0300
commite09c706bfbcb03e83705a85516f400a086c02369 (patch)
tree08ee373246a75b4cd57728f8dd12c7a2aa435547 /drivers/leds
parentc47d14545b991064b1dd15906cfb413dbc2780ac (diff)
downloadlinux-e09c706bfbcb03e83705a85516f400a086c02369.tar.xz
leds: trigger: Load trigger modules on-demand if used as default trigger
Even if a trigger is set as default trigger for a LED device, the respective trigger module (if built as module) isn't automatically loaded by the kernel if the LED device is registered. I think we can do better. Try to load the module asynchronously by alias ledtrig:<trigger name>. This requires that such an alias is added to relevant triggers. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Link: https://lore.kernel.org/r/79adb260-06ad-443a-a68e-abe4498c3298@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/led-triggers.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index bd59a14a4a90..71cb0aee528c 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -250,6 +250,7 @@ EXPORT_SYMBOL_GPL(led_trigger_remove);
void led_trigger_set_default(struct led_classdev *led_cdev)
{
struct led_trigger *trig;
+ bool found = false;
if (!led_cdev->default_trigger)
return;
@@ -259,6 +260,7 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
list_for_each_entry(trig, &trigger_list, next_trig) {
if (!strcmp(led_cdev->default_trigger, trig->name) &&
trigger_relevant(led_cdev, trig)) {
+ found = true;
led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER;
led_trigger_set(led_cdev, trig);
break;
@@ -266,6 +268,13 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
}
up_write(&led_cdev->trigger_lock);
up_read(&triggers_list_lock);
+
+ /*
+ * If default trigger wasn't found, maybe trigger module isn't loaded yet.
+ * Once loaded it will re-probe with all led_cdev's.
+ */
+ if (!found)
+ request_module_nowait("ledtrig:%s", led_cdev->default_trigger);
}
EXPORT_SYMBOL_GPL(led_trigger_set_default);