Skip to contentSkip to conversation

Make lib/bug.c WARN implementation match the kernel/panic.c one

PATCH In review Anton Blanchard 2 participants 3 messages Jun 26, 2010 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Make lib/bug.c WARN implementation match the kernel/panic.c one

There are a few issues with the exception based WARN implementation in lib/bug.c:

- Inconsistent printk flags. The "cut here" line is printed at KERN_EMERG, so the console and all logged in users see the single line:

------------[ cut here ]------------

for each WARN. Fix this so we print everything at KERN_WARNING to match the kernel/panic.c version.

- The lib/bug.c WARN would print "Badness at". Change it to match the kernel/panic.c version which prints "WARNING: at".

- Print the list of modules, similar to kernel/panic.c of modules, similar to kernel/panic.c

---

lib/bug.c +7 -4
Index: linux-2.6/lib/bug.c
===================================================================
@@ -136,8 +136,6 @@ enum bug_trap_type report_bug(unsigned l
 
 	bug = find_bug(bugaddr);
 
-	printk(KERN_EMERG "------------[ cut here ]------------\n");
-
 	file = NULL;
 	line = 0;
 	warning = 0;
@@ -156,19 +154,24 @@ enum bug_trap_type report_bug(unsigned l
 
 	if (warning) {
 		/* this is a WARN_ON rather than BUG/BUG_ON */
+		printk(KERN_WARNING "------------[ cut here ]------------\n");
+
 		if (file)
-			printk(KERN_ERR "Badness at %s:%u\n",
+			printk(KERN_WARNING "WARNING: at %s:%u\n",
 			       file, line);
 		else
-			printk(KERN_ERR "Badness at %p "
+			printk(KERN_WARNING "WARNING: at %p "
 			       "[verbose debug info unavailable]\n",
 			       (void *)bugaddr);
 
+        	print_modules();
 		show_regs(regs);
 		add_taint(BUG_GET_TAINT(bug));
 		return BUG_TRAP_TYPE_WARN;
 	}
 
+	printk(KERN_EMERG "------------[ cut here ]------------\n");
+
 	if (file)
 		printk(KERN_CRIT "kernel BUG at %s:%u!\n",
 		       file, line);
#1 lore raw

PATCH 2/2 Add oops end marker to lib/bug.c WARN implementation

We are missing the oops end marker for the exception based WARN implementation in lib/bug.c. This is useful for logfile analysis tools.

---

include/linux/kernel.h +1 -0
Index: linux-2.6/include/linux/kernel.h
===================================================================
@@ -177,6 +177,7 @@ NORET_TYPE void panic(const char * fmt, 
 	__attribute__ ((NORET_AND format (printf, 1, 2))) __cold;
 extern void oops_enter(void);
 extern void oops_exit(void);
+void print_oops_end_marker(void);
 extern int oops_may_print(void);
 NORET_TYPE void do_exit(long error_code)
 	ATTRIB_NORET;
kernel/panic.c +1 -1
Index: linux-2.6/kernel/panic.c
===================================================================
@@ -344,7 +344,7 @@ static int init_oops_id(void)
 }
 late_initcall(init_oops_id);
 
-static void print_oops_end_marker(void)
+void print_oops_end_marker(void)
 {
 	init_oops_id();
 	printk(KERN_WARNING "---[ end trace %016llx ]---\n",
lib/bug.c +1 -0
Index: linux-2.6/lib/bug.c
===================================================================
@@ -166,6 +166,7 @@ enum bug_trap_type report_bug(unsigned l
 
         	print_modules();
 		show_regs(regs);
+		print_oops_end_marker();
 		add_taint(BUG_GET_TAINT(bug));
 		return BUG_TRAP_TYPE_WARN;
 	}
#2 lore raw
In reply to Anton Blanchard
Quoted 48 lines · Anton Blanchard

There are a few issues with the exception based WARN implementation in lib/bug.c:

- Inconsistent printk flags. The "cut here" line is printed at KERN_EMERG, so the console and all logged in users see the single line:

------------[ cut here ]------------

for each WARN. Fix this so we print everything at KERN_WARNING to match the kernel/panic.c version.

- The lib/bug.c WARN would print "Badness at". Change it to match the kernel/panic.c version which prints "WARNING: at".

- Print the list of modules, similar to kernel/panic.c of modules, similar to kernel/panic.c

---

Index: linux-2.6/lib/bug.c
===================================================================

lib/bug.c +4 -4
@@ -136,8 +136,6 @@ enum bug_trap_type report_bug(unsigned l
 
 	bug = find_bug(bugaddr);
 
-	printk(KERN_EMERG "------------[ cut here ]------------\n");
-
 	file = NULL;
 	line = 0;
 	warning = 0;
@@ -156,19 +154,24 @@ enum bug_trap_type report_bug(unsigned l
 
 	if (warning) {
 		/* this is a WARN_ON rather than BUG/BUG_ON */
+		printk(KERN_WARNING "------------[ cut here ]------------\n");
+
 		if (file)
-			printk(KERN_ERR "Badness at %s:%u\n",
+			printk(KERN_WARNING "WARNING: at %s:%u\n",
 			       file, line);
 		else
-			printk(KERN_ERR "Badness at %p "
+			printk(KERN_WARNING "WARNING: at %p "
 			       "[verbose debug info unavailable]\n",

lib/bug.c enum bug_trap_type report_bug(unsigned l · line 174

Quoted 10 lines
lib/bug.c +3 -0
 			       (void *)bugaddr);
 
+        	print_modules();
 		show_regs(regs);
 		add_taint(BUG_GET_TAINT(bug));
 		return BUG_TRAP_TYPE_WARN;
 	}
 
+	printk(KERN_EMERG "------------[ cut here ]------------\n");
+

Hm... Why do you use KERN_EMERG here?

Quoted 8 lines
lib/bug.c +0 -1
 	if (file)
 		printk(KERN_CRIT "kernel BUG at %s:%u!\n",
 		       file, line);
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
 Kirill A. Shutemov