Skip to contentSkip to conversation

Fix dev_printk to work with unclaimed devices

PATCH In review Deepak Saxena 3 participants 4 messages Feb 26, 2004 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix dev_printk to work with unclaimed devices

I need to do some fixup in platform_notify() and when trying to use the dev_* print functions for informational messages, they OOPs b/c the current code assumes that dev->driver exists. This is not the case since platform_notify() is called before a device has been attached to any driver.

include/linux/device.h +7 -1
@@ -395,7 +395,13 @@
 
 /* debugging and troubleshooting/diagnostic helpers. */
 #define dev_printk(level, dev, format, arg...)	\
-	printk(level "%s %s: " format , (dev)->driver->name , (dev)->bus_id , ## arg)
+	do {					\
+		if ((dev)->driver) {		\
+			printk(level "%s %s: " format , (dev)->driver->name , (dev)->bus_id , ## arg);				\
+		} else {			\
+			printk(level "%s (Unclaimed %s bus device): " format , (dev)->bus_id, (dev)->bus->name , ## arg);					\
+		}				\
+	} while (0)
 
 #ifdef DEBUG
 #define dev_dbg(dev, format, arg...)		\
#1 lore raw
Quoted 6 lines · Deepak Saxena

I need to do some fixup in platform_notify() and when trying to use the dev_* print functions for informational messages, they OOPs b/c the current code assumes that dev->driver exists. This is not the case since platform_notify() is called before a device has been attached to any driver.

Make it a real function with varags, please.

On the other hand, it also is probably just _wrong_ to use "dev_printk()" if you aren't the driver for the device.

Linus

#2 lore raw
In reply to Deepak Saxena
Quoted 6 lines · Deepak Saxena

I need to do some fixup in platform_notify() and when trying to use the dev_* print functions for informational messages, they OOPs b/c the current code assumes that dev->driver exists. This is not the case since platform_notify() is called before a device has been attached to any driver.

Yeah, this "limitation" of the dev_* printks have been known for a while, and it was determined that for situations like this, it's not worth using those calls.

I have a patch somewhere in my tree that will give you a nice WARN() output if this ever happens, so as to help when trying to port a new bus to the driver model, but it's too ugly for mainline. Ah, found it, it's below...

thanks,

greg k-h

include/linux/device.h +12 -0
diff -Nru a/include/linux/device.h b/include/linux/device.h
@@ -394,8 +394,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...)		\
#3 lore raw

On Feb 26 2004, at 10:53, Greg KH was caught saying:

Quoted 11 lines · Deepak Saxena
Quoted 6 lines

I need to do some fixup in platform_notify() and when trying to use the dev_* print functions for informational messages, they OOPs b/c the current code assumes that dev->driver exists. This is not the case since platform_notify() is called before a device has been attached to any driver.

Yeah, this "limitation" of the dev_* printks have been known for a while, and it was determined that for situations like this, it's not worth using those calls.

I can just use printks as it is only two quick log messages at init time.

Tnx,
~Deepak

Signature · 1 line
Deepak Saxena - dsaxena at plexity dot net - http://www.plexity.net/