public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, linux-usb-devel@lists.sourceforge.net
Subject: [PATCH] add CONFIG_DEBUG_DEV_PRINTK
Date: Tue, 15 Apr 2003 00:37:07 -0700	[thread overview]
Message-ID: <20030415073707.GA9416@kroah.com> (raw)

Ok, I don't want to remember how many times I've gotten burned by the
dev_printk() function while developing drivers, as it doesn't check for
valid pointers before dereferencing them.  So here's a patch I've
started using that might help out any kernel driver developers in the
same situation.  For device busses that support hotplug, this patch is a
lifesaver (the dev->driver pointer has a fun habit of going away pretty
early during disconnect...)

I'm not pushing for submission to the main kernel tree, unless others
really feel it's useful.

greg k-h


# 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...)		\

                 reply	other threads:[~2003-04-15  7:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030415073707.GA9416@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox