All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds: heartbeat: stop on shutdown
@ 2012-04-24 13:43 Alexander Holler
  2012-04-24 15:07 ` [PATCH v2] " Alexander Holler
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 13:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Richard Purdie, Alexander Holler

A halted kernel should not show a heartbeat.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/leds/ledtrig-heartbeat.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index 759c0bb..76189b0 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -18,6 +18,7 @@
 #include <linux/timer.h>
 #include <linux/sched.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
 #include "leds.h"
 
 struct heartbeat_trig_data {
@@ -101,13 +102,26 @@ static struct led_trigger heartbeat_led_trigger = {
 	.deactivate = heartbeat_trig_deactivate,
 };
 
+static int heartbeat_reboot_notifier(struct notifier_block *nb,
+				     unsigned long code, void *unused)
+{
+	led_trigger_unregister(&heartbeat_led_trigger);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block heartbeat_reboot_nb = {
+	.notifier_call = heartbeat_reboot_notifier,
+};
+
 static int __init heartbeat_trig_init(void)
 {
+	register_reboot_notifier(&heartbeat_reboot_nb);
 	return led_trigger_register(&heartbeat_led_trigger);
 }
 
 static void __exit heartbeat_trig_exit(void)
 {
+	unregister_reboot_notifier(&heartbeat_reboot_nb);
 	led_trigger_unregister(&heartbeat_led_trigger);
 }
 
-- 
1.7.6.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 13:43 [PATCH] leds: heartbeat: stop on shutdown Alexander Holler
@ 2012-04-24 15:07 ` Alexander Holler
  2012-04-24 15:24   ` Shuah Khan
  2012-04-24 22:30   ` [PATCH v3] leds: heartbeat: stop on shutdown, reboot or panic Alexander Holler
  0 siblings, 2 replies; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 15:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: Richard Purdie, Alexander Holler

A halted kernel should not show a heartbeat.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index 759c0bb..1c05bd9 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -18,6 +18,7 @@
 #include <linux/timer.h>
 #include <linux/sched.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
 #include "leds.h"
 
 struct heartbeat_trig_data {
@@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
 	.deactivate = heartbeat_trig_deactivate,
 };
 
+static int heartbeat_reboot_notifier(struct notifier_block *nb,
+				     unsigned long code, void *unused)
+{
+	led_trigger_unregister(&heartbeat_led_trigger);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block heartbeat_reboot_nb = {
+	.notifier_call = heartbeat_reboot_notifier,
+};
+
 static int __init heartbeat_trig_init(void)
 {
-	return led_trigger_register(&heartbeat_led_trigger);
+	int rc = led_trigger_register(&heartbeat_led_trigger);
+	if( ! rc )
+		register_reboot_notifier(&heartbeat_reboot_nb);
+	return rc;
 }
 
 static void __exit heartbeat_trig_exit(void)
 {
+	unregister_reboot_notifier(&heartbeat_reboot_nb);
 	led_trigger_unregister(&heartbeat_led_trigger);
 }
 
-- 
1.7.6.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 15:07 ` [PATCH v2] " Alexander Holler
@ 2012-04-24 15:24   ` Shuah Khan
  2012-04-24 16:32     ` Alexander Holler
  2012-04-24 22:30   ` [PATCH v3] leds: heartbeat: stop on shutdown, reboot or panic Alexander Holler
  1 sibling, 1 reply; 10+ messages in thread
From: Shuah Khan @ 2012-04-24 15:24 UTC (permalink / raw)
  To: Alexander Holler; +Cc: shuahkhan, linux-kernel, Richard Purdie

On Tue, 2012-04-24 at 17:07 +0200, Alexander Holler wrote:
> A halted kernel should not show a heartbeat.
> 
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> ---
>  drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
>  1 files changed, 17 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
> index 759c0bb..1c05bd9 100644
> --- a/drivers/leds/ledtrig-heartbeat.c
> +++ b/drivers/leds/ledtrig-heartbeat.c
> @@ -18,6 +18,7 @@
>  #include <linux/timer.h>
>  #include <linux/sched.h>
>  #include <linux/leds.h>
> +#include <linux/reboot.h>
>  #include "leds.h"
>  
>  struct heartbeat_trig_data {
> @@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
>  	.deactivate = heartbeat_trig_deactivate,
>  };
>  
> +static int heartbeat_reboot_notifier(struct notifier_block *nb,
> +				     unsigned long code, void *unused)
> +{
> +	led_trigger_unregister(&heartbeat_led_trigger);
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block heartbeat_reboot_nb = {
> +	.notifier_call = heartbeat_reboot_notifier,
> +};
> +
>  static int __init heartbeat_trig_init(void)
>  {
> -	return led_trigger_register(&heartbeat_led_trigger);
> +	int rc = led_trigger_register(&heartbeat_led_trigger);
> +	if( ! rc )
> +		register_reboot_notifier(&heartbeat_reboot_nb);

Do you need to check return value here? I see return value being checked
in some places in the kernel and not in others. Not checking is fine for
now since register_reboot_notifier() always returns 0. 

Maybe adding return handling might not be a bad idea to be consistent
with other places that do check.

FYI - Andrew Morton is handling led patches these days. You might want
to send include him  <akpm@linux-foundation.org>

> +	return rc;
>  }
>  
>  static void __exit heartbeat_trig_exit(void)
>  {
> +	unregister_reboot_notifier(&heartbeat_reboot_nb);
>  	led_trigger_unregister(&heartbeat_led_trigger);
>  }
>  



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 15:24   ` Shuah Khan
@ 2012-04-24 16:32     ` Alexander Holler
  2012-04-24 17:00       ` Shuah Khan
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 16:32 UTC (permalink / raw)
  To: shuahkhan; +Cc: linux-kernel, Richard Purdie, Andrew Morton

Am 24.04.2012 17:24, schrieb Shuah Khan:
> On Tue, 2012-04-24 at 17:07 +0200, Alexander Holler wrote:
>> A halted kernel should not show a heartbeat.
>>
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>> ---
>>  drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
>>  1 files changed, 17 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
>> index 759c0bb..1c05bd9 100644
>> --- a/drivers/leds/ledtrig-heartbeat.c
>> +++ b/drivers/leds/ledtrig-heartbeat.c
>> @@ -18,6 +18,7 @@
>>  #include <linux/timer.h>
>>  #include <linux/sched.h>
>>  #include <linux/leds.h>
>> +#include <linux/reboot.h>
>>  #include "leds.h"
>>  
>>  struct heartbeat_trig_data {
>> @@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
>>  	.deactivate = heartbeat_trig_deactivate,
>>  };
>>  
>> +static int heartbeat_reboot_notifier(struct notifier_block *nb,
>> +				     unsigned long code, void *unused)
>> +{
>> +	led_trigger_unregister(&heartbeat_led_trigger);
>> +	return NOTIFY_DONE;
>> +}
>> +
>> +static struct notifier_block heartbeat_reboot_nb = {
>> +	.notifier_call = heartbeat_reboot_notifier,
>> +};
>> +
>>  static int __init heartbeat_trig_init(void)
>>  {
>> -	return led_trigger_register(&heartbeat_led_trigger);
>> +	int rc = led_trigger_register(&heartbeat_led_trigger);
>> +	if( ! rc )
>> +		register_reboot_notifier(&heartbeat_reboot_nb);
> 
> Do you need to check return value here? I see return value being checked
> in some places in the kernel and not in others. Not checking is fine for
> now since register_reboot_notifier() always returns 0.
> 
> Maybe adding return handling might not be a bad idea to be consistent
> with other places that do check.

What to do if it fails? As long as unregister_reboot_notifier() doesn't
do something bad with non-registered notifiers (which it doesn't), I
would let the init still succeed. And to not unregister a
non-registered-reboot_notifier, a long-living bool would be needed.

> FYI - Andrew Morton is handling led patches these days. You might want
> to send include him  <akpm@linux-foundation.org>

I have added him to CC, thanks.

Regards,

Alexander

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 16:32     ` Alexander Holler
@ 2012-04-24 17:00       ` Shuah Khan
  2012-04-24 17:27         ` Alexander Holler
  0 siblings, 1 reply; 10+ messages in thread
From: Shuah Khan @ 2012-04-24 17:00 UTC (permalink / raw)
  To: Alexander Holler; +Cc: shuahkhan, linux-kernel, Richard Purdie, Andrew Morton

On Tue, 2012-04-24 at 18:32 +0200, Alexander Holler wrote:
> Am 24.04.2012 17:24, schrieb Shuah Khan:
> > On Tue, 2012-04-24 at 17:07 +0200, Alexander Holler wrote:
> >> A halted kernel should not show a heartbeat.
> >>
> >> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> >> ---
> >>  drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
> >>  1 files changed, 17 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
> >> index 759c0bb..1c05bd9 100644
> >> --- a/drivers/leds/ledtrig-heartbeat.c
> >> +++ b/drivers/leds/ledtrig-heartbeat.c
> >> @@ -18,6 +18,7 @@
> >>  #include <linux/timer.h>
> >>  #include <linux/sched.h>
> >>  #include <linux/leds.h>
> >> +#include <linux/reboot.h>
> >>  #include "leds.h"
> >>  
> >>  struct heartbeat_trig_data {
> >> @@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
> >>  	.deactivate = heartbeat_trig_deactivate,
> >>  };
> >>  
> >> +static int heartbeat_reboot_notifier(struct notifier_block *nb,
> >> +				     unsigned long code, void *unused)
> >> +{
> >> +	led_trigger_unregister(&heartbeat_led_trigger);
> >> +	return NOTIFY_DONE;
> >> +}
I am sorry I didn't catch this the last time. Do you need to call
unregister here? Looks like trigger is going away with a registered
reboot notifier. Might be fine, since reboot is going to happen.

> >> +
> >> +static struct notifier_block heartbeat_reboot_nb = {
> >> +	.notifier_call = heartbeat_reboot_notifier,
> >> +};
> >> +
> >>  static int __init heartbeat_trig_init(void)
> >>  {
> >> -	return led_trigger_register(&heartbeat_led_trigger);
> >> +	int rc = led_trigger_register(&heartbeat_led_trigger);
> >> +	if( ! rc )
> >> +		register_reboot_notifier(&heartbeat_reboot_nb);
> > 
> > Do you need to check return value here? I see return value being checked
> > in some places in the kernel and not in others. Not checking is fine for
> > now since register_reboot_notifier() always returns 0.
> > 
> > Maybe adding return handling might not be a bad idea to be consistent
> > with other places that do check.
> 
> What to do if it fails? As long as unregister_reboot_notifier() doesn't
> do something bad with non-registered notifiers (which it doesn't), I
> would let the init still succeed. 

Yes I agree that init should still succeed. It might be helpful to throw
out a kernel message when this occurs though since register shouldn't
fail unless there is an error.

> And to not unregister a
> non-registered-reboot_notifier, a long-living bool would be needed.

Yes keeping state is probably required to unregister conditionally.
Since unregistering is safe (simply returns -ENOENT) when called after
register fails. So I would think you can call unregister even when
register fails. 

-- Shuah




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 17:00       ` Shuah Khan
@ 2012-04-24 17:27         ` Alexander Holler
  2012-04-24 17:31           ` Shuah Khan
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 17:27 UTC (permalink / raw)
  To: shuahkhan; +Cc: linux-kernel, Richard Purdie, Andrew Morton

Am 24.04.2012 19:00, schrieb Shuah Khan:
> On Tue, 2012-04-24 at 18:32 +0200, Alexander Holler wrote:
>> Am 24.04.2012 17:24, schrieb Shuah Khan:
>>> On Tue, 2012-04-24 at 17:07 +0200, Alexander Holler wrote:
>>>> A halted kernel should not show a heartbeat.
>>>>
>>>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>>>> ---
>>>>  drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
>>>>  1 files changed, 17 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
>>>> index 759c0bb..1c05bd9 100644
>>>> --- a/drivers/leds/ledtrig-heartbeat.c
>>>> +++ b/drivers/leds/ledtrig-heartbeat.c
>>>> @@ -18,6 +18,7 @@
>>>>  #include <linux/timer.h>
>>>>  #include <linux/sched.h>
>>>>  #include <linux/leds.h>
>>>> +#include <linux/reboot.h>
>>>>  #include "leds.h"
>>>>  
>>>>  struct heartbeat_trig_data {
>>>> @@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
>>>>  	.deactivate = heartbeat_trig_deactivate,
>>>>  };
>>>>  
>>>> +static int heartbeat_reboot_notifier(struct notifier_block *nb,
>>>> +				     unsigned long code, void *unused)
>>>> +{
>>>> +	led_trigger_unregister(&heartbeat_led_trigger);
>>>> +	return NOTIFY_DONE;
>>>> +}
> I am sorry I didn't catch this the last time. Do you need to call
> unregister here? Looks like trigger is going away with a registered
> reboot notifier. Might be fine, since reboot is going to happen.

That unregister is the whole reason of the patch because it disables all
running heartbeats on reboot/shutdown. ;)

I still wonder why the timers are running after a kernel halted (so the
heardbeat was still alive), but there might be a good reason not just to
disable all running timers unconditionally on shutdown.

Regards,

Alexander

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 17:27         ` Alexander Holler
@ 2012-04-24 17:31           ` Shuah Khan
  2012-04-24 17:34             ` Alexander Holler
  0 siblings, 1 reply; 10+ messages in thread
From: Shuah Khan @ 2012-04-24 17:31 UTC (permalink / raw)
  To: Alexander Holler; +Cc: shuahkhan, linux-kernel, Richard Purdie, Andrew Morton

On Tue, 2012-04-24 at 19:27 +0200, Alexander Holler wrote:
> Am 24.04.2012 19:00, schrieb Shuah Khan:
> > On Tue, 2012-04-24 at 18:32 +0200, Alexander Holler wrote:
> >> Am 24.04.2012 17:24, schrieb Shuah Khan:
> >>> On Tue, 2012-04-24 at 17:07 +0200, Alexander Holler wrote:
> >>>> A halted kernel should not show a heartbeat.
> >>>>
> >>>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> >>>> ---
> >>>>  drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
> >>>>  1 files changed, 17 insertions(+), 1 deletions(-)
> >>>>
> >>>> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
> >>>> index 759c0bb..1c05bd9 100644
> >>>> --- a/drivers/leds/ledtrig-heartbeat.c
> >>>> +++ b/drivers/leds/ledtrig-heartbeat.c
> >>>> @@ -18,6 +18,7 @@
> >>>>  #include <linux/timer.h>
> >>>>  #include <linux/sched.h>
> >>>>  #include <linux/leds.h>
> >>>> +#include <linux/reboot.h>
> >>>>  #include "leds.h"
> >>>>  
> >>>>  struct heartbeat_trig_data {
> >>>> @@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
> >>>>  	.deactivate = heartbeat_trig_deactivate,
> >>>>  };
> >>>>  
> >>>> +static int heartbeat_reboot_notifier(struct notifier_block *nb,
> >>>> +				     unsigned long code, void *unused)
> >>>> +{
> >>>> +	led_trigger_unregister(&heartbeat_led_trigger);
> >>>> +	return NOTIFY_DONE;
> >>>> +}
> > I am sorry I didn't catch this the last time. Do you need to call
> > unregister here? Looks like trigger is going away with a registered
> > reboot notifier. Might be fine, since reboot is going to happen.
> 
> That unregister is the whole reason of the patch because it disables all
> running heartbeats on reboot/shutdown. ;)

Sorry I should have been clear about which unregister. I meant
unregister_reboot_notifier()
> 
> I still wonder why the timers are running after a kernel halted (so the
> heardbeat was still alive), but there might be a good reason not just to
> disable all running timers unconditionally on shutdown.
> 
> Regards,
> 
> Alexander
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] leds: heartbeat: stop on shutdown
  2012-04-24 17:31           ` Shuah Khan
@ 2012-04-24 17:34             ` Alexander Holler
  0 siblings, 0 replies; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 17:34 UTC (permalink / raw)
  To: shuahkhan; +Cc: linux-kernel, Richard Purdie, Andrew Morton

Am 24.04.2012 19:31, schrieb Shuah Khan:
> On Tue, 2012-04-24 at 19:27 +0200, Alexander Holler wrote:
>> Am 24.04.2012 19:00, schrieb Shuah Khan:
>>> On Tue, 2012-04-24 at 18:32 +0200, Alexander Holler wrote:
>>>> Am 24.04.2012 17:24, schrieb Shuah Khan:
>>>>> On Tue, 2012-04-24 at 17:07 +0200, Alexander Holler wrote:
>>>>>> A halted kernel should not show a heartbeat.
>>>>>>
>>>>>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>>>>>> ---
>>>>>>  drivers/leds/ledtrig-heartbeat.c |   18 +++++++++++++++++-
>>>>>>  1 files changed, 17 insertions(+), 1 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
>>>>>> index 759c0bb..1c05bd9 100644
>>>>>> --- a/drivers/leds/ledtrig-heartbeat.c
>>>>>> +++ b/drivers/leds/ledtrig-heartbeat.c
>>>>>> @@ -18,6 +18,7 @@
>>>>>>  #include <linux/timer.h>
>>>>>>  #include <linux/sched.h>
>>>>>>  #include <linux/leds.h>
>>>>>> +#include <linux/reboot.h>
>>>>>>  #include "leds.h"
>>>>>>  
>>>>>>  struct heartbeat_trig_data {
>>>>>> @@ -101,13 +102,28 @@ static struct led_trigger heartbeat_led_trigger = {
>>>>>>  	.deactivate = heartbeat_trig_deactivate,
>>>>>>  };
>>>>>>  
>>>>>> +static int heartbeat_reboot_notifier(struct notifier_block *nb,
>>>>>> +				     unsigned long code, void *unused)
>>>>>> +{
>>>>>> +	led_trigger_unregister(&heartbeat_led_trigger);
>>>>>> +	return NOTIFY_DONE;
>>>>>> +}
>>> I am sorry I didn't catch this the last time. Do you need to call
>>> unregister here? Looks like trigger is going away with a registered
>>> reboot notifier. Might be fine, since reboot is going to happen.
>>
>> That unregister is the whole reason of the patch because it disables all
>> running heartbeats on reboot/shutdown. ;)
> 
> Sorry I should have been clear about which unregister. I meant
> unregister_reboot_notifier()

That is needed in case the module will be unloaded.

Regards,

Alexander

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3] leds: heartbeat: stop on shutdown, reboot or panic
  2012-04-24 15:07 ` [PATCH v2] " Alexander Holler
  2012-04-24 15:24   ` Shuah Khan
@ 2012-04-24 22:30   ` Alexander Holler
  2012-04-24 22:38     ` [PATCH v4] " Alexander Holler
  1 sibling, 1 reply; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 22:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: Richard Purdie, Andrew Morton, Alexander Holler

A halted kernel should not show a heartbeat.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/leds/ledtrig-heartbeat.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index 759c0bb..8cfa7df 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -18,6 +18,7 @@
 #include <linux/timer.h>
 #include <linux/sched.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
 #include "leds.h"
 
 struct heartbeat_trig_data {
@@ -101,13 +102,37 @@ static struct led_trigger heartbeat_led_trigger = {
 	.deactivate = heartbeat_trig_deactivate,
 };
 
+static int heartbeat_reboot_notifier(struct notifier_block *nb,
+				     unsigned long code, void *unused)
+{
+	led_trigger_unregister(&heartbeat_led_trigger);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block heartbeat_reboot_nb = {
+	.notifier_call = heartbeat_reboot_notifier,
+};
+
+static struct notifier_block heartbeat_panic_nb = {
+	.notifier_call = heartbeat_reboot_notifier,
+};
+
 static int __init heartbeat_trig_init(void)
 {
-	return led_trigger_register(&heartbeat_led_trigger);
+	int rc = led_trigger_register(&heartbeat_led_trigger);
+	if( ! rc ) {
+		atomic_notifier_chain_register(&panic_notifier_list,
+					       &heartbeat_panic_nb);
+		register_reboot_notifier(&heartbeat_reboot_nb);
+	}
+	return rc;
 }
 
 static void __exit heartbeat_trig_exit(void)
 {
+	unregister_reboot_notifier(&heartbeat_reboot_nb);
+	atomic_notifier_chain_unregister(&panic_notifier_list,
+					 &heartbeat_panic_nb);
 	led_trigger_unregister(&heartbeat_led_trigger);
 }
 
-- 
1.7.6.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4] leds: heartbeat: stop on shutdown, reboot or panic
  2012-04-24 22:30   ` [PATCH v3] leds: heartbeat: stop on shutdown, reboot or panic Alexander Holler
@ 2012-04-24 22:38     ` Alexander Holler
  0 siblings, 0 replies; 10+ messages in thread
From: Alexander Holler @ 2012-04-24 22:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Richard Purdie, Andrew Morton, Alexander Holler

A halted kernel should not show a heartbeat.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 drivers/leds/ledtrig-heartbeat.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index 759c0bb..31c234c 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -18,6 +18,7 @@
 #include <linux/timer.h>
 #include <linux/sched.h>
 #include <linux/leds.h>
+#include <linux/reboot.h>
 #include "leds.h"
 
 struct heartbeat_trig_data {
@@ -101,13 +102,37 @@ static struct led_trigger heartbeat_led_trigger = {
 	.deactivate = heartbeat_trig_deactivate,
 };
 
+static int heartbeat_reboot_notifier(struct notifier_block *nb,
+				     unsigned long code, void *unused)
+{
+	led_trigger_unregister(&heartbeat_led_trigger);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block heartbeat_reboot_nb = {
+	.notifier_call = heartbeat_reboot_notifier,
+};
+
+static struct notifier_block heartbeat_panic_nb = {
+	.notifier_call = heartbeat_reboot_notifier,
+};
+
 static int __init heartbeat_trig_init(void)
 {
-	return led_trigger_register(&heartbeat_led_trigger);
+	int rc = led_trigger_register(&heartbeat_led_trigger);
+	if (!rc) {
+		atomic_notifier_chain_register(&panic_notifier_list,
+					       &heartbeat_panic_nb);
+		register_reboot_notifier(&heartbeat_reboot_nb);
+	}
+	return rc;
 }
 
 static void __exit heartbeat_trig_exit(void)
 {
+	unregister_reboot_notifier(&heartbeat_reboot_nb);
+	atomic_notifier_chain_unregister(&panic_notifier_list,
+					 &heartbeat_panic_nb);
 	led_trigger_unregister(&heartbeat_led_trigger);
 }
 
-- 
1.7.6.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-04-24 22:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-24 13:43 [PATCH] leds: heartbeat: stop on shutdown Alexander Holler
2012-04-24 15:07 ` [PATCH v2] " Alexander Holler
2012-04-24 15:24   ` Shuah Khan
2012-04-24 16:32     ` Alexander Holler
2012-04-24 17:00       ` Shuah Khan
2012-04-24 17:27         ` Alexander Holler
2012-04-24 17:31           ` Shuah Khan
2012-04-24 17:34             ` Alexander Holler
2012-04-24 22:30   ` [PATCH v3] leds: heartbeat: stop on shutdown, reboot or panic Alexander Holler
2012-04-24 22:38     ` [PATCH v4] " Alexander Holler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.