From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] ARM: Do not print exception stacktrace in panic
Date: Thu, 9 Mar 2023 15:26:31 +0100 [thread overview]
Message-ID: <20230309142631.338244-1-s.hauer@pengutronix.de> (raw)
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@pengutronix.de>
---
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
reply other threads:[~2023-03-09 14:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230309142631.338244-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox