lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 13 Feb 2021 16:47:36 +0100
From:   Alexander Sverdlin <alexander.sverdlin@...il.com>
To:     linux-leds@...r.kernel.org
Cc:     Alexander Sverdlin <alexander.sverdlin@...il.com>,
        Pavel Machek <pavel@....cz>, Dan Murphy <dmurphy@...com>,
        linux-kernel@...r.kernel.org
Subject: [PATCH] leds: trigger: timer: Optionally stop timer trigger on reboot

This functionality is similar to heartbeat and activity triggers and
turns the timer-triggered LEDs off right before reboot. It's configurable
via new module parameter "reboot_off" to preserve original behaviour.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@...il.com>
---
 drivers/leds/trigger/ledtrig-timer.c | 39 +++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/trigger/ledtrig-timer.c b/drivers/leds/trigger/ledtrig-timer.c
index 7c14983781ee..3eadcb0a629a 100644
--- a/drivers/leds/trigger/ledtrig-timer.c
+++ b/drivers/leds/trigger/ledtrig-timer.c
@@ -16,6 +16,11 @@
 #include <linux/device.h>
 #include <linux/ctype.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
+
+static bool reboot_off;
+module_param(reboot_off, bool, 0444);
+MODULE_PARM_DESC(reboot_off, "Switch LED off on reboot");
 
 static ssize_t led_delay_on_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -97,7 +102,39 @@ static struct led_trigger timer_led_trigger = {
 	.deactivate = timer_trig_deactivate,
 	.groups = timer_trig_groups,
 };
-module_led_trigger(timer_led_trigger);
+
+static int timer_reboot_notifier(struct notifier_block *nb, unsigned long code,
+				 void *unused)
+{
+	led_trigger_unregister(&timer_led_trigger);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block timer_reboot_nb = {
+	.notifier_call = timer_reboot_notifier,
+};
+
+static int __init timer_trig_init(void)
+{
+	int ret;
+
+	ret = led_trigger_register(&timer_led_trigger);
+	if (ret)
+		return ret;
+	if (reboot_off)
+		register_reboot_notifier(&timer_reboot_nb);
+	return 0;
+}
+
+static void __exit timer_trig_exit(void)
+{
+	/* Not afraid of -ENOENT */
+	unregister_reboot_notifier(&timer_reboot_nb);
+	led_trigger_unregister(&timer_led_trigger);
+}
+
+module_init(timer_trig_init);
+module_exit(timer_trig_exit);
 
 MODULE_AUTHOR("Richard Purdie <rpurdie@...nedhand.com>");
 MODULE_DESCRIPTION("Timer LED trigger");
-- 
2.19.1

Powered by blists - more mailing lists