panic() prints a stacktrace by default. When being called in a an exception this will print the stacktrace of the exception stack which is not useful, so drop it. We are printing the desired stacktrace anyway before calling panic(). Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- arch/arm/cpu/interrupts.c | 2 +- arch/arm/cpu/interrupts_64.c | 2 +- common/misc.c | 29 +++++++++++++++++++++++------ include/printk.h | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/arch/arm/cpu/interrupts.c b/arch/arm/cpu/interrupts.c index a1728eb353..5bc790a796 100644 --- a/arch/arm/cpu/interrupts.c +++ b/arch/arm/cpu/interrupts.c @@ -68,7 +68,7 @@ static void __noreturn do_exception(struct pt_regs *pt_regs) { show_regs(pt_regs); - panic(""); + panic_no_stacktrace(""); } /** diff --git a/arch/arm/cpu/interrupts_64.c b/arch/arm/cpu/interrupts_64.c index f54fdcd3dd..d844915fee 100644 --- a/arch/arm/cpu/interrupts_64.c +++ b/arch/arm/cpu/interrupts_64.c @@ -88,7 +88,7 @@ static void __noreturn do_exception(struct pt_regs *pt_regs) unwind_backtrace(pt_regs); - panic("panic: unhandled exception"); + panic_no_stacktrace("panic: unhandled exception"); } /** diff --git a/common/misc.c b/common/misc.c index 400c1fb48f..e266f0951e 100644 --- a/common/misc.c +++ b/common/misc.c @@ -216,15 +216,13 @@ device_initcall(of_kernel_init); BAREBOX_MAGICVAR(global.of.kernel.add_machine_compatible, "Additional machine/board compatible"); -void __noreturn panic(const char *fmt, ...) +static void __noreturn do_panic(bool stacktrace, const char *fmt, va_list ap) { - va_list args; - va_start(args, fmt); - vprintf(fmt, args); + vprintf(fmt, ap); putchar('\n'); - va_end(args); - dump_stack(); + if (stacktrace) + dump_stack(); led_trigger(LED_TRIGGER_PANIC, TRIGGER_ENABLE); @@ -235,4 +233,23 @@ void __noreturn panic(const char *fmt, ...) restart_machine(); } } + +void __noreturn panic(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + do_panic(true, fmt, args); + va_end(args); +} EXPORT_SYMBOL(panic); + +void __noreturn panic_no_stacktrace(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + do_panic(false, fmt, args); + va_end(args); +} +EXPORT_SYMBOL(panic_no_stacktrace); diff --git a/include/printk.h b/include/printk.h index 6f8635fae2..bf9645249d 100644 --- a/include/printk.h +++ b/include/printk.h @@ -28,6 +28,7 @@ static inline int printf(const char *fmt, ...) #endif void __attribute__((noreturn)) panic(const char *fmt, ...); +void __attribute__((noreturn)) panic_no_stacktrace(const char *fmt, ...); #define printk printf -- 2.30.2