The trigger core learned error handling for the activate callback and to handle device attributes. This allows to simplify the driver considerably. Note that .deactivate is only called when .new_activate succeeded, so the check for trigger_data being non-NULL can go away. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx> --- drivers/leds/trigger/ledtrig-timer.c | 39 ++++++++++------------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-timer.c b/drivers/leds/trigger/ledtrig-timer.c index 8d09327b5719..d3f0f056f492 100644 --- a/drivers/leds/trigger/ledtrig-timer.c +++ b/drivers/leds/trigger/ledtrig-timer.c @@ -71,45 +71,32 @@ static ssize_t led_delay_off_store(struct device *dev, static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store); static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store); -static void timer_trig_activate(struct led_classdev *led_cdev) -{ - int rc; - - led_cdev->trigger_data = NULL; - - rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); - if (rc) - return; - rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); - if (rc) - goto err_out_delayon; +static struct attribute *timer_trig_attrs[] = { + &dev_attr_delay_on.attr, + &dev_attr_delay_off.attr, + NULL +}; +ATTRIBUTE_GROUPS(timer_trig); +static int timer_trig_activate(struct led_classdev *led_cdev) +{ led_blink_set(led_cdev, &led_cdev->blink_delay_on, &led_cdev->blink_delay_off); - led_cdev->activated = true; - - return; -err_out_delayon: - device_remove_file(led_cdev->dev, &dev_attr_delay_on); + return 0; } static void timer_trig_deactivate(struct led_classdev *led_cdev) { - if (led_cdev->activated) { - device_remove_file(led_cdev->dev, &dev_attr_delay_on); - device_remove_file(led_cdev->dev, &dev_attr_delay_off); - led_cdev->activated = false; - } - /* Stop blinking */ led_set_brightness(led_cdev, LED_OFF); } static struct led_trigger timer_led_trigger = { - .name = "timer", - .activate = timer_trig_activate, + .name = "timer", + .new_activate = timer_trig_activate, .deactivate = timer_trig_deactivate, + .groups = timer_trig_groups, }; static int __init timer_trig_init(void) @@ -127,4 +114,4 @@ module_exit(timer_trig_exit); MODULE_AUTHOR("Richard Purdie <rpurdie@xxxxxxxxxxxxxx>"); MODULE_DESCRIPTION("Timer LED trigger"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); -- 2.17.0