From patchwork Thu Apr 28 22:03:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 8975661 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8F668BF29F for ; Thu, 28 Apr 2016 22:05:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C83220268 for ; Thu, 28 Apr 2016 22:05:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A615E2015A for ; Thu, 28 Apr 2016 22:05:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1avu2u-0004UL-DH; Thu, 28 Apr 2016 22:04:28 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1avu2k-0004QN-Q3 for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2016 22:04:19 +0000 Received: by mail-pa0-x230.google.com with SMTP id zm5so41519940pac.0 for ; Thu, 28 Apr 2016 15:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y3WyBiyHrfEGAxGL42FHnu8aeQrAf+D78EfA0OSiBOE=; b=0JuAggcMRuXkLBZc916q+bbVvxE7A60qK51hV6uT3/nmdUDISW8wFYgwj50EOm5V03 +Z2RZ0PvrCv3pFtlm3cH0ZtVmySReK4sfYGzCftGEeQisZNZxnVlg5j97rJRyZrkC0t2 s3SV1SmZI0CY4Y1pmOsrp68P7i+f6Jv1YcbB/8YNecdCs95vPc1uW5va3oOEh8A9XOzq IoP8MB5bDKvPzWj5/L2BsB3+TldIGsTxY1VkZFLlyHCR3nno6an4YEMe7WFm7qc3x6Uu s3aJhuOjBazyQ3OCeiXBO1+ViMfb16sOWq2Z+0cLxpX9uJElVP7rZBu0tFA5SGd/IMqP jCow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y3WyBiyHrfEGAxGL42FHnu8aeQrAf+D78EfA0OSiBOE=; b=B4O/CGJ6nOE7Kf2KgKnP6hkYretU3RPSMo3kH3PGHigvvXxSlntA2lgDS88PZAy53H VW9UnXsHyrQ7zKlVWXEgjb3Um5VVDGL3LfGZ91vMzpnlDZ7NZ8b5/cM+c2ucSYY4uyKv +ZJt0Xgiez14I9awPWVg8cWjLt8PmDtE44Ag3FV4vththUNN7Ps7mwwNSIAyCJ9Y8EGa mRiZf/p0olc4lZRh7REamTunqPl4U0ddXgCeVWSjyh2StDeXvIfU6E3ZKPq9PeFV6NhD tyb+B5TFwC72tx59PYD/vMLIyxs7PxOqjjaHE+DKNr7DB98W+YDbwK5mR1WrH+jEA848 0yiw== X-Gm-Message-State: AOPr4FULLV8ngAUA3INyhN7wckdqILGtCWQqLHO3OpOrtEcW79ATGn05xLN/n251xystsQ== X-Received: by 10.66.172.165 with SMTP id bd5mr24457869pac.128.1461881038195; Thu, 28 Apr 2016 15:03:58 -0700 (PDT) Received: from localhost.localdomain ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id g84sm17609045pfj.42.2016.04.28.15.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Apr 2016 15:03:56 -0700 (PDT) From: Ezequiel Garcia To: , , , Subject: [PATCH v3 1/3] leds: triggers: Allow to switch the trigger to "panic" on a kernel panic Date: Thu, 28 Apr 2016 19:03:38 -0300 Message-Id: <1461881020-13964-2-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1461881020-13964-1-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1461881020-13964-1-git-send-email-ezequiel@vanguardiasur.com.ar> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160428_150418_889230_1FEAE83E X-CRM114-Status: GOOD ( 21.40 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Pawel Moll , Ian Campbell , Rob Herring , Richard Purdie , Ezequiel Garcia , Pavel Machek , Kumar Gala , Jacek Anaszewski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit adds a new led_cdev flag LED_PANIC_INDICATOR, 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 | 2 +- drivers/leds/leds.h | 1 + drivers/leds/trigger/Kconfig | 3 +++ drivers/leds/trigger/ledtrig-panic.c | 47 ++++++++++++++++++++++++++++++++++++ include/linux/leds.h | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 2181581795d3..55fa65e1ae03 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -26,7 +26,7 @@ * Nests outside led_cdev->trigger_lock */ static DECLARE_RWSEM(triggers_list_lock); -static LIST_HEAD(trigger_list); +LIST_HEAD(trigger_list); /* Used by LED Class */ diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index db3f20da7221..7d38e6b9a740 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h @@ -30,5 +30,6 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev, extern struct rw_semaphore leds_list_lock; extern struct list_head leds_list; +extern struct list_head trigger_list; #endif /* __LEDS_H_INCLUDED */ diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig index beac8c31c51b..4e4521c9072a 100644 --- a/drivers/leds/trigger/Kconfig +++ b/drivers/leds/trigger/Kconfig @@ -121,6 +121,9 @@ config LEDS_TRIGGER_PANIC depends on LEDS_TRIGGERS help This allows LEDs to be configured to blink on a kernel panic. + Enabling this option will allow to mark certain LEDs as 'panic-indicators', + allowing to blink them on a kernel panic, even if they are set to + a different trigger. If unsure, say Y. endif # LEDS_TRIGGERS diff --git a/drivers/leds/trigger/ledtrig-panic.c b/drivers/leds/trigger/ledtrig-panic.c index 627b350c5ec3..3e447bd2064a 100644 --- a/drivers/leds/trigger/ledtrig-panic.c +++ b/drivers/leds/trigger/ledtrig-panic.c @@ -11,10 +11,54 @@ #include #include +#include #include +#include "../leds.h" static struct led_trigger *trigger; +/* + * 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); + + /* Avoid the delayed blink path */ + led_cdev->blink_delay_on = 0; + led_cdev->blink_delay_off = 0; + + 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_PANIC_INDICATOR) + led_trigger_set_panic(led_cdev); + return NOTIFY_DONE; +} + +static struct notifier_block led_trigger_panic_nb = { + .notifier_call = led_trigger_panic_notifier, +}; + static long led_panic_blink(int state) { led_trigger_event(trigger, state ? LED_FULL : LED_OFF); @@ -23,6 +67,9 @@ static long led_panic_blink(int state) static int __init ledtrig_panic_init(void) { + atomic_notifier_chain_register(&panic_notifier_list, + &led_trigger_panic_nb); + led_trigger_register_simple("panic", &trigger); panic_blink = led_panic_blink; return 0; diff --git a/include/linux/leds.h b/include/linux/leds.h index 19eb10278bea..7e9fb00e15e8 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_PANIC_INDICATOR (1 << 25) /* Set LED brightness level * Must not sleep. Use brightness_set_blocking for drivers