Fix dev_printk to work with unclaimed devices
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...) \
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 thatdev->driverexists. This is not the case sinceplatform_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
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 thatdev->driverexists. This is not the case sinceplatform_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
@@ -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...) \
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 thatdev->driverexists. This is not the case sinceplatform_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/