1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-25 17:53:34 -05:00

leds: triggers: Add helper led_match_default_trigger

Avoid code duplication and factor out common functionality to new
helper led_match_default_trigger().

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://lore.kernel.org/r/d78eef6f-c18c-4546-b83e-6d1890849154@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Heiner Kallweit 2024-01-31 15:33:08 +01:00 committed by Lee Jones
parent e838a5a110
commit 9225333e48

View file

@ -247,6 +247,19 @@ void led_trigger_remove(struct led_classdev *led_cdev)
} }
EXPORT_SYMBOL_GPL(led_trigger_remove); EXPORT_SYMBOL_GPL(led_trigger_remove);
static bool led_match_default_trigger(struct led_classdev *led_cdev,
struct led_trigger *trig)
{
if (!strcmp(led_cdev->default_trigger, trig->name) &&
trigger_relevant(led_cdev, trig)) {
led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER;
led_trigger_set(led_cdev, trig);
return true;
}
return false;
}
void led_trigger_set_default(struct led_classdev *led_cdev) void led_trigger_set_default(struct led_classdev *led_cdev)
{ {
struct led_trigger *trig; struct led_trigger *trig;
@ -258,13 +271,9 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
down_read(&triggers_list_lock); down_read(&triggers_list_lock);
down_write(&led_cdev->trigger_lock); down_write(&led_cdev->trigger_lock);
list_for_each_entry(trig, &trigger_list, next_trig) { list_for_each_entry(trig, &trigger_list, next_trig) {
if (!strcmp(led_cdev->default_trigger, trig->name) && found = led_match_default_trigger(led_cdev, trig);
trigger_relevant(led_cdev, trig)) { if (found)
found = true;
led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER;
led_trigger_set(led_cdev, trig);
break; break;
}
} }
up_write(&led_cdev->trigger_lock); up_write(&led_cdev->trigger_lock);
up_read(&triggers_list_lock); up_read(&triggers_list_lock);
@ -306,12 +315,8 @@ int led_trigger_register(struct led_trigger *trig)
down_read(&leds_list_lock); down_read(&leds_list_lock);
list_for_each_entry(led_cdev, &leds_list, node) { list_for_each_entry(led_cdev, &leds_list, node) {
down_write(&led_cdev->trigger_lock); down_write(&led_cdev->trigger_lock);
if (!led_cdev->trigger && led_cdev->default_trigger && if (!led_cdev->trigger && led_cdev->default_trigger)
!strcmp(led_cdev->default_trigger, trig->name) && led_match_default_trigger(led_cdev, trig);
trigger_relevant(led_cdev, trig)) {
led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER;
led_trigger_set(led_cdev, trig);
}
up_write(&led_cdev->trigger_lock); up_write(&led_cdev->trigger_lock);
} }
up_read(&leds_list_lock); up_read(&leds_list_lock);