leds: trigger: panic: Don't register panic notifier if creating the trigger failed
authorHeiner Kallweit <hkallweit1@gmail.com>
Sat, 16 Dec 2023 20:05:33 +0000 (21:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Feb 2024 20:14:30 +0000 (20:14 +0000)
[ Upstream commit afacb21834bb02785ddb0c3ec197208803b74faa ]

It doesn't make sense to register the panic notifier if creating the
panic trigger failed.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://lore.kernel.org/r/8a61e229-5388-46c7-919a-4d18cc7362b2@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/leds/trigger/ledtrig-panic.c

index 64abf2e..5a6b21b 100644 (file)
@@ -64,10 +64,13 @@ static long led_panic_blink(int state)
 
 static int __init ledtrig_panic_init(void)
 {
+       led_trigger_register_simple("panic", &trigger);
+       if (!trigger)
+               return -ENOMEM;
+
        atomic_notifier_chain_register(&panic_notifier_list,
                                       &led_trigger_panic_nb);
 
-       led_trigger_register_simple("panic", &trigger);
        panic_blink = led_panic_blink;
        return 0;
 }