From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Machek Subject: Re: [PATCH 1/5] leds: triggers: Allow to switch the trigger to "panic" on a kernel panic Date: Sun, 24 Apr 2016 11:25:52 +0200 Message-ID: <20160424092551.GB23015@amd> References: <1459801326-5541-1-git-send-email-ezequiel@vanguardiasur.com.ar> <1459801326-5541-2-git-send-email-ezequiel@vanguardiasur.com.ar> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:53049 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752408AbcDXJZy (ORCPT ); Sun, 24 Apr 2016 05:25:54 -0400 Content-Disposition: inline In-Reply-To: <1459801326-5541-2-git-send-email-ezequiel@vanguardiasur.com.ar> Sender: linux-leds-owner@vger.kernel.org List-Id: linux-leds@vger.kernel.org To: Ezequiel Garcia Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Richard Purdie , Jacek Anaszewski On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote: > This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which > allows to mark a specific LED to be switched to the "panic" > trigger, on a kernel panic. > > This is useful to allow the user to assign a regular trigger > to a given LED, and still blink that LED on a kernel panic. > > Signed-off-by: Ezequiel Garcia > drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ > include/linux/leds.h | 1 + Could we get this out of the core? I'm pretty sure most users are not interested... Pavel > +/* > + * This is a called in a special context by the atomic panic > + * notifier. This means the trigger can be changed without > + * worrying about locking. > + */ > +static void led_trigger_set_panic(struct led_classdev *led_cdev) > +{ > + struct led_trigger *trig; > + > + list_for_each_entry(trig, &trigger_list, next_trig) { > + if (strcmp("panic", trig->name)) > + continue; > + if (led_cdev->trigger) > + list_del(&led_cdev->trig_list); > + list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); > + led_cdev->trigger = trig; > + if (trig->activate) > + trig->activate(led_cdev); > + break; > + } > +} > + > +static int led_trigger_panic_notifier(struct notifier_block *nb, > + unsigned long code, void *unused) > +{ > + struct led_classdev *led_cdev; > + > + list_for_each_entry(led_cdev, &leds_list, node) > + if (led_cdev->flags & LED_BLINK_AT_PANIC) > + led_trigger_set_panic(led_cdev); > + return NOTIFY_DONE; > +} > + > +static struct notifier_block led_trigger_panic_nb = { > + .notifier_call = led_trigger_panic_notifier, > +}; > + > void led_trigger_set_default(struct led_classdev *led_cdev) > { > struct led_trigger *trig; > @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig) > } > EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); > > +static int __init leds_trigger_init(void) > +{ > + atomic_notifier_chain_register(&panic_notifier_list, > + &led_trigger_panic_nb); > + return 0; > +} > + > +static void __exit leds_trigger_exit(void) > +{ > + atomic_notifier_chain_unregister(&panic_notifier_list, > + &led_trigger_panic_nb); > +} > +module_init(leds_trigger_init); > +module_exit(leds_trigger_exit); > + > MODULE_AUTHOR("Richard Purdie"); > MODULE_LICENSE("GPL"); > MODULE_DESCRIPTION("LED Triggers Core"); > diff --git a/include/linux/leds.h b/include/linux/leds.h > index f203a8f89d30..7f1428bb1e69 100644 > --- a/include/linux/leds.h > +++ b/include/linux/leds.h > @@ -50,6 +50,7 @@ struct led_classdev { > #define LED_SYSFS_DISABLE (1 << 22) > #define LED_DEV_CAP_FLASH (1 << 23) > #define LED_HW_PLUGGABLE (1 << 24) > +#define LED_BLINK_AT_PANIC (1 << 25) > > /* Set LED brightness level > * Must not sleep. Use brightness_set_blocking for drivers -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: pavel@ucw.cz (Pavel Machek) Date: Sun, 24 Apr 2016 11:25:52 +0200 Subject: [PATCH 1/5] leds: triggers: Allow to switch the trigger to "panic" on a kernel panic In-Reply-To: <1459801326-5541-2-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1459801326-5541-1-git-send-email-ezequiel@vanguardiasur.com.ar> <1459801326-5541-2-git-send-email-ezequiel@vanguardiasur.com.ar> Message-ID: <20160424092551.GB23015@amd> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Mon 2016-04-04 17:22:02, Ezequiel Garcia wrote: > This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which > allows to mark a specific LED to be switched to the "panic" > trigger, on a kernel panic. > > This is useful to allow the user to assign a regular trigger > to a given LED, and still blink that LED on a kernel panic. > > Signed-off-by: Ezequiel Garcia > drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ > include/linux/leds.h | 1 + Could we get this out of the core? I'm pretty sure most users are not interested... Pavel > +/* > + * This is a called in a special context by the atomic panic > + * notifier. This means the trigger can be changed without > + * worrying about locking. > + */ > +static void led_trigger_set_panic(struct led_classdev *led_cdev) > +{ > + struct led_trigger *trig; > + > + list_for_each_entry(trig, &trigger_list, next_trig) { > + if (strcmp("panic", trig->name)) > + continue; > + if (led_cdev->trigger) > + list_del(&led_cdev->trig_list); > + list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); > + led_cdev->trigger = trig; > + if (trig->activate) > + trig->activate(led_cdev); > + break; > + } > +} > + > +static int led_trigger_panic_notifier(struct notifier_block *nb, > + unsigned long code, void *unused) > +{ > + struct led_classdev *led_cdev; > + > + list_for_each_entry(led_cdev, &leds_list, node) > + if (led_cdev->flags & LED_BLINK_AT_PANIC) > + led_trigger_set_panic(led_cdev); > + return NOTIFY_DONE; > +} > + > +static struct notifier_block led_trigger_panic_nb = { > + .notifier_call = led_trigger_panic_notifier, > +}; > + > void led_trigger_set_default(struct led_classdev *led_cdev) > { > struct led_trigger *trig; > @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig) > } > EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); > > +static int __init leds_trigger_init(void) > +{ > + atomic_notifier_chain_register(&panic_notifier_list, > + &led_trigger_panic_nb); > + return 0; > +} > + > +static void __exit leds_trigger_exit(void) > +{ > + atomic_notifier_chain_unregister(&panic_notifier_list, > + &led_trigger_panic_nb); > +} > +module_init(leds_trigger_init); > +module_exit(leds_trigger_exit); > + > MODULE_AUTHOR("Richard Purdie"); > MODULE_LICENSE("GPL"); > MODULE_DESCRIPTION("LED Triggers Core"); > diff --git a/include/linux/leds.h b/include/linux/leds.h > index f203a8f89d30..7f1428bb1e69 100644 > --- a/include/linux/leds.h > +++ b/include/linux/leds.h > @@ -50,6 +50,7 @@ struct led_classdev { > #define LED_SYSFS_DISABLE (1 << 22) > #define LED_DEV_CAP_FLASH (1 << 23) > #define LED_HW_PLUGGABLE (1 << 24) > +#define LED_BLINK_AT_PANIC (1 << 25) > > /* Set LED brightness level > * Must not sleep. Use brightness_set_blocking for drivers -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html