[patch] printk: add KERN_CONT annotation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Willy Tarreau <[email protected]> wrote:

> Well, I think that we could do something like this :
> 
> #define KERN_CONT ""
> ...
> 	printk(KERN_ERR "foo");
> 	<100 lines of whatever>
> 	printk(KERN_CONT "bar\n");
> 
> It would indicate the author's *intent* which is to continue a line 
> which has already been started. It would both permit us to remove 
> false positives from automated scripts, and to read the code more 
> easily. And this is not a big constaint for the author, given that 
> such constructs are quite rare.

ah, this is even nicer than the raw_printk() thing i suggested, and it 
also nicely documents the intention of the author. Patch attached below.

And i'd like to stress the principle that is followed here: in this 
particular case the checkpatch.pl warning is very useful, but still 
there are false positives. Fortunately they are so rare that it's worth 
annotating those few exceptions in the source. Note that the goal is 
still to be able to achieve 100% warning-free source code. _That_ should 
be the driving principle behind checkpatch.pl warnings.

	Ingo

------------------>
Subject: printk: add KERN_CONT annotation
From: Ingo Molnar <[email protected]>

printk: add the KERN_CONT annotation (which is empty string but via 
which checkpatch.pl can notice that the lacking KERN_ level is fine). 
This useful for multiple calls of hand-crafted printk output done by 
early debug code or similar.

Signed-off-by: Ingo Molnar <[email protected]>
---
 include/linux/kernel.h |    7 +++++++
 kernel/sched.c         |   22 +++++++++++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)

Index: linux/include/linux/kernel.h
===================================================================
--- linux.orig/include/linux/kernel.h
+++ linux/include/linux/kernel.h
@@ -61,6 +61,13 @@ extern const char linux_proc_banner[];
 #define	KERN_INFO	"<6>"	/* informational			*/
 #define	KERN_DEBUG	"<7>"	/* debug-level messages			*/
 
+/*
+ * Annotation for a "continued" line of log printout (only done after a
+ * line that had no enclosing \n). Only to be used by core/arch code
+ * during early bootup (a continued line is not SMP-safe otherwise).
+ */
+#define	KERN_CONT	""
+
 extern int console_printk[];
 
 #define console_loglevel (console_printk[0])
Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c
+++ linux/kernel/sched.c
@@ -4770,18 +4770,18 @@ static void show_task(struct task_struct
 	unsigned state;
 
 	state = p->state ? __ffs(p->state) + 1 : 0;
-	printk("%-13.13s %c", p->comm,
+	printk(KERN_INFO "%-13.13s %c", p->comm,
 		state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
 #if BITS_PER_LONG == 32
 	if (state == TASK_RUNNING)
-		printk(" running  ");
+		printk(KERN_CONT " running  ");
 	else
-		printk(" %08lx ", thread_saved_pc(p));
+		printk(KERN_CONT " %08lx ", thread_saved_pc(p));
 #else
 	if (state == TASK_RUNNING)
-		printk("  running task    ");
+		printk(KERN_CONT "  running task    ");
 	else
-		printk(" %016lx ", thread_saved_pc(p));
+		printk(KERN_CONT " %016lx ", thread_saved_pc(p));
 #endif
 #ifdef CONFIG_DEBUG_STACK_USAGE
 	{
@@ -4791,7 +4791,7 @@ static void show_task(struct task_struct
 		free = (unsigned long)n - (unsigned long)end_of_stack(p);
 	}
 #endif
-	printk("%5lu %5d %6d\n", free, p->pid, p->parent->pid);
+	printk(KERN_CONT "%5lu %5d %6d\n", free, p->pid, p->parent->pid);
 
 	if (state != TASK_RUNNING)
 		show_stack(p, NULL);
@@ -5527,20 +5527,20 @@ static void sched_domain_debug(struct sc
 			}
 
 			if (!group->__cpu_power) {
-				printk("\n");
+				printk(KERN_CONT "\n");
 				printk(KERN_ERR "ERROR: domain->cpu_power not "
 						"set\n");
 				break;
 			}
 
 			if (!cpus_weight(group->cpumask)) {
-				printk("\n");
+				printk(KERN_CONT "\n");
 				printk(KERN_ERR "ERROR: empty group\n");
 				break;
 			}
 
 			if (cpus_intersects(groupmask, group->cpumask)) {
-				printk("\n");
+				printk(KERN_CONT "\n");
 				printk(KERN_ERR "ERROR: repeated CPUs\n");
 				break;
 			}
@@ -5548,11 +5548,11 @@ static void sched_domain_debug(struct sc
 			cpus_or(groupmask, groupmask, group->cpumask);
 
 			cpumask_scnprintf(str, NR_CPUS, group->cpumask);
-			printk(" %s", str);
+			printk(KERN_CONT " %s", str);
 
 			group = group->next;
 		} while (group != sd->groups);
-		printk("\n");
+		printk(KERN_CONT "\n");
 
 		if (!cpus_equal(sd->span, groupmask))
 			printk(KERN_ERR "ERROR: groups don't span "
-
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/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux