public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: remove unneeded endless loop in BUG()
@ 2009-02-19 18:38 Petr Tesarik
  2009-02-19 18:40 ` H. Peter Anvin
  2009-02-19 18:59 ` Ingo Molnar
  0 siblings, 2 replies; 9+ messages in thread
From: Petr Tesarik @ 2009-02-19 18:38 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Jeremy Fitzhardinge, H. Peter Anvin, LKML

Since __builtin_trap() will always generate an illegal instruction, we
can replace the explicit asm("ud2") with it.

This way gcc will understand that the function never returns, plus it
won't emit any extra instructions.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
index d9cf1cd..9b7c50a 100644
--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -4,6 +4,13 @@
 #ifdef CONFIG_BUG
 #define HAVE_ARCH_BUG
 
+#define DO_BUG()						\
+do {								\
+	__builtin_trap();					\
+	printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
+	panic("BUG!");						\
+} while(0)
+
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 
 #ifdef CONFIG_X86_32
@@ -14,7 +21,7 @@
 
 #define BUG()							\
 do {								\
-	asm volatile("1:\tud2\n"				\
+	asm volatile("1:\n"					\
 		     ".pushsection __bug_table,\"a\"\n"		\
 		     __BUG_C0					\
 		     "\t.word %c1, 0\n"				\
@@ -22,15 +29,11 @@ do {								\
 		     ".popsection"				\
 		     : : "i" (__FILE__), "i" (__LINE__),	\
 		     "i" (sizeof(struct bug_entry)));		\
-	for (;;) ;						\
+	DO_BUG();					\
 } while (0)
 
 #else
-#define BUG()							\
-do {								\
-	asm volatile("ud2");					\
-	for (;;) ;						\
-} while (0)
+#define BUG	DO_BUG
 #endif
 
 #endif /* !CONFIG_BUG */



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-02-20  8:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-19 18:38 [PATCH] x86: remove unneeded endless loop in BUG() Petr Tesarik
2009-02-19 18:40 ` H. Peter Anvin
2009-02-19 18:59 ` Ingo Molnar
2009-02-19 19:53   ` H. Peter Anvin
2009-02-19 20:47     ` Jeremy Fitzhardinge
2009-02-19 20:48       ` H. Peter Anvin
2009-02-20  8:28         ` Petr Tesarik
2009-02-19 20:29   ` H. Peter Anvin
2009-02-19 20:32     ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox