]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
panic: Add vpanic()
authorNam Cao <namcao@linutronix.de>
Wed, 9 Jul 2025 19:21:14 +0000 (21:21 +0200)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 9 Jul 2025 19:27:00 +0000 (15:27 -0400)
vpanic() is useful for implementing runtime verification reactors. Add it.

Signed-off-by: Nam Cao <namcao@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
include/linux/panic.h
kernel/panic.c

index 4adc6576693549e31f85750e698ad294ec0aaaf0..0332c6d6771fbf8c174a58ae9391453373c2b139 100644 (file)
@@ -3,6 +3,7 @@
 #define _LINUX_PANIC_H
 
 #include <linux/compiler_attributes.h>
+#include <linux/stdarg.h>
 #include <linux/types.h>
 
 struct pt_regs;
@@ -10,6 +11,8 @@ struct pt_regs;
 extern long (*panic_blink)(int state);
 __printf(1, 2)
 void panic(const char *fmt, ...) __noreturn __cold;
+__printf(1, 0)
+void vpanic(const char *fmt, va_list args) __noreturn __cold;
 void nmi_panic(struct pt_regs *regs, const char *msg);
 void check_panic_on_warn(const char *origin);
 extern void oops_enter(void);
index b0b9a8bf4560d5d0139dd74ee9a037bdfeb12c54..6a1823c383d0176db85e57b56dee5849c3fef782 100644 (file)
@@ -309,13 +309,13 @@ static void panic_other_cpus_shutdown(bool crash_kexec)
 /**
  * panic - halt the system
  * @fmt: The text string to print
+ * @args: Arguments for the format string
  *
  * Display a message, then perform cleanups. This function never returns.
  */
-void panic(const char *fmt, ...)
+void vpanic(const char *fmt, va_list args)
 {
        static char buf[1024];
-       va_list args;
        long i, i_next = 0, len;
        int state = 0;
        int old_cpu, this_cpu;
@@ -366,9 +366,7 @@ void panic(const char *fmt, ...)
 
        console_verbose();
        bust_spinlocks(1);
-       va_start(args, fmt);
        len = vscnprintf(buf, sizeof(buf), fmt, args);
-       va_end(args);
 
        if (len && buf[len - 1] == '\n')
                buf[len - 1] = '\0';
@@ -505,7 +503,17 @@ void panic(const char *fmt, ...)
                mdelay(PANIC_TIMER_STEP);
        }
 }
+EXPORT_SYMBOL(vpanic);
 
+/* Identical to vpanic(), except it takes variadic arguments instead of va_list */
+void panic(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vpanic(fmt, args);
+       va_end(args);
+}
 EXPORT_SYMBOL(panic);
 
 #define TAINT_FLAG(taint, _c_true, _c_false, _module)                  \