Skip to content

Commit 49dca5a

Browse files
ahollertorvalds
authored andcommitted
leds: heartbeat: stop on shutdown
A halted kernel should not show a heartbeat. [[email protected]: checkpatch fixes] Signed-off-by: Alexander Holler <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Richard Purdie <[email protected]> Cc: Bryan Wu <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6335f8f commit 49dca5a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

drivers/leds/ledtrig-heartbeat.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/timer.h>
1919
#include <linux/sched.h>
2020
#include <linux/leds.h>
21+
#include <linux/reboot.h>
2122
#include "leds.h"
2223

2324
struct heartbeat_trig_data {
@@ -103,13 +104,38 @@ static struct led_trigger heartbeat_led_trigger = {
103104
.deactivate = heartbeat_trig_deactivate,
104105
};
105106

107+
static int heartbeat_reboot_notifier(struct notifier_block *nb,
108+
unsigned long code, void *unused)
109+
{
110+
led_trigger_unregister(&heartbeat_led_trigger);
111+
return NOTIFY_DONE;
112+
}
113+
114+
static struct notifier_block heartbeat_reboot_nb = {
115+
.notifier_call = heartbeat_reboot_notifier,
116+
};
117+
118+
static struct notifier_block heartbeat_panic_nb = {
119+
.notifier_call = heartbeat_reboot_notifier,
120+
};
121+
106122
static int __init heartbeat_trig_init(void)
107123
{
108-
return led_trigger_register(&heartbeat_led_trigger);
124+
int rc = led_trigger_register(&heartbeat_led_trigger);
125+
126+
if (!rc) {
127+
atomic_notifier_chain_register(&panic_notifier_list,
128+
&heartbeat_panic_nb);
129+
register_reboot_notifier(&heartbeat_reboot_nb);
130+
}
131+
return rc;
109132
}
110133

111134
static void __exit heartbeat_trig_exit(void)
112135
{
136+
unregister_reboot_notifier(&heartbeat_reboot_nb);
137+
atomic_notifier_chain_unregister(&panic_notifier_list,
138+
&heartbeat_panic_nb);
113139
led_trigger_unregister(&heartbeat_led_trigger);
114140
}
115141

0 commit comments

Comments
 (0)