public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] Add PR_PREFIX to pr_xyz macros.
@ 2008-11-12 17:35 Martin Schwidefsky
  2008-11-12 19:48 ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Schwidefsky @ 2008-11-12 17:35 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

Hi Linus,
there is one spin-off from the kernel message patches I would still
like to get upstream: replacing all the different printk macros in the
s390 device drivers with dev_xyz and pr_xyz.

One thing the s390 printk macros have been doing which I miss with the
pr_xyz macros is a way to automatically prefix the messages with the 
driver name. This is quite handy, saves some typing and shortens the
printk line. The pr_xyz macros could be taught about a prefix, would
something like the patch below be acceptable?
The idea is to add a '#define PR_PREFIX "driver"' to the start of the
source file and have the pr_xyz macros paste the prefix to each message.

-- 
blue skies,
  Martin.

"Reality continues to ruin my life." - Calvin.

---
Subject: [PATCH] Add PR_PREFIX to pr_xyz macros.

From: Martin Schwidefsky <schwidefsky@de.ibm.com>

A common reason for device drivers to implement their own printk macros
is the lack of a printk prefix with the standard pr_xyz macros. The most
common use of the prefix would be to add the name of the device driver to
all printks in a source file.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---
 include/linux/kernel.h |   44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff -urpN linux-2.6/include/linux/kernel.h linux-2.6-patched/include/linux/kernel.h
--- linux-2.6/include/linux/kernel.h	2008-11-11 16:59:04.000000000 +0100
+++ linux-2.6-patched/include/linux/kernel.h	2008-11-11 17:19:04.000000000 +0100
@@ -318,32 +318,38 @@ static inline char *pack_hex_byte(char *
 	return buf;
 }
 
-#define pr_emerg(fmt, arg...) \
-	printk(KERN_EMERG fmt, ##arg)
-#define pr_alert(fmt, arg...) \
-	printk(KERN_ALERT fmt, ##arg)
-#define pr_crit(fmt, arg...) \
-	printk(KERN_CRIT fmt, ##arg)
-#define pr_err(fmt, arg...) \
-	printk(KERN_ERR fmt, ##arg)
-#define pr_warning(fmt, arg...) \
-	printk(KERN_WARNING fmt, ##arg)
-#define pr_notice(fmt, arg...) \
-	printk(KERN_NOTICE fmt, ##arg)
-#define pr_info(fmt, arg...) \
-	printk(KERN_INFO fmt, ##arg)
+#ifndef PR_PREFIX
+#define pr_fmt(format) format 
+#else
+#define pr_fmt(format) PR_PREFIX ": " format
+#endif
+
+#define pr_emerg(fmt, ...) \
+        printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert(fmt, ...) \
+        printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit(fmt, ...) \
+        printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err(fmt, ...) \
+        printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning(fmt, ...) \
+        printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_notice(fmt, ...) \
+        printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info(fmt, ...) \
+        printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
 
 /* If you are writing a driver, please use dev_dbg instead */
 #if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
 #define pr_debug(fmt, ...) do { \
-	dynamic_pr_debug(fmt, ##__VA_ARGS__); \
+	dynamic_pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \
 	} while (0)
 #elif defined(DEBUG)
-#define pr_debug(fmt, arg...) \
-	printk(KERN_DEBUG fmt, ##arg)
+#define pr_debug(fmt, ...) \
+	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
 #else
-#define pr_debug(fmt, arg...) \
-	({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
+#define pr_debug(fmt, ...) \
+	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
 #endif
 
 /*



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

end of thread, other threads:[~2008-11-15  8:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 17:35 [RFC] Add PR_PREFIX to pr_xyz macros Martin Schwidefsky
2008-11-12 19:48 ` Linus Torvalds
2008-11-12 19:59   ` Martin Schwidefsky
2008-11-12 20:16   ` Martin Schwidefsky
2008-11-14 21:32     ` Andrew Morton
2008-11-15  8:58       ` Martin Schwidefsky

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