From foo@baz Tue Apr  9 12:12:43 2002
To: Greg KH <greg@kroah.com>
Date: 14 Apr 2003 11:45:02 -07:00
From: greg@kroah.com
Subject: added CONFIG_DEBUG_DEV_PRINTK option to keep my sanity during development.

diff -Nru a/arch/i386/Kconfig b/arch/i386/Kconfig
--- a/arch/i386/Kconfig	Mon Apr 14 11:46:36 2003
+++ b/arch/i386/Kconfig	Mon Apr 14 11:46:36 2003
@@ -1504,6 +1504,13 @@
 	  This options enables addition error checking for high memory systems.
 	  Disable for production systems.
 
+config DEBUG_DEV_PRINTK
+	bool "Debug dev_printk"
+	depends on DEBUG_KERNEL
+	help
+	  If you say Y here, all dev_printk() parameters will be checked before
+	  dev_printk() is called.  This is useful when debugging new drivers.
+
 config KALLSYMS
 	bool "Load all symbols for debugging/kksymoops"
 	help
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	Mon Apr 14 11:46:36 2003
+++ b/include/linux/device.h	Mon Apr 14 11:46:36 2003
@@ -379,8 +379,20 @@
 extern void firmware_unregister(struct subsystem *);
 
 /* debugging and troubleshooting/diagnostic helpers. */
+#ifdef CONFIG_DEBUG_DEV_PRINTK
+#define dev_printk(level, dev, format, arg...)			\
+	do {							\
+		if (!(dev) || !(dev)->driver)			\
+			WARN_ON(1);				\
+		else						\
+			printk(level "%s %s: " format , 	\
+				(dev)->driver->name , 		\
+				(dev)->bus_id , ## arg);	\
+	} while (0)
+#else
 #define dev_printk(level, dev, format, arg...)	\
 	printk(level "%s %s: " format , (dev)->driver->name , (dev)->bus_id , ## arg)
+#endif
 
 #ifdef DEBUG
 #define dev_dbg(dev, format, arg...)		\
