Skip to content

Commit 3e95637

Browse files
AlanSterngregkh
authored andcommitted
[PATCH] Driver Core: Make dev_info and friends print the bus name if there is no driver
This patch (as721) makes dev_info and related macros print the device's bus name if the device doesn't have a driver, instead of printing just a blank. If the device isn't on a bus either... well, then it does leave a blank space. But it will be easier for someone else to change if they want. Cc: Matthew Wilcox <[email protected]> Signed-off-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e9a7d30 commit 3e95637

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

drivers/base/core.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ int (*platform_notify_remove)(struct device * dev) = NULL;
2929
* sysfs bindings for devices.
3030
*/
3131

32+
/**
33+
* dev_driver_string - Return a device's driver name, if at all possible
34+
* @dev: struct device to get the name of
35+
*
36+
* Will return the device's driver's name if it is bound to a device. If
37+
* the device is not bound to a device, it will return the name of the bus
38+
* it is attached to. If it is not attached to a bus either, an empty
39+
* string will be returned.
40+
*/
41+
const char *dev_driver_string(struct device *dev)
42+
{
43+
return dev->driver ? dev->driver->name :
44+
(dev->bus ? dev->bus->name : "");
45+
}
46+
EXPORT_SYMBOL_GPL(dev_driver_string);
47+
3248
#define to_dev(obj) container_of(obj, struct device, kobj)
3349
#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
3450

include/linux/device.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,9 @@ extern int firmware_register(struct subsystem *);
416416
extern void firmware_unregister(struct subsystem *);
417417

418418
/* debugging and troubleshooting/diagnostic helpers. */
419+
extern const char *dev_driver_string(struct device *dev);
419420
#define dev_printk(level, dev, format, arg...) \
420-
printk(level "%s %s: " format , (dev)->driver ? (dev)->driver->name : "" , (dev)->bus_id , ## arg)
421+
printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)
421422

422423
#ifdef DEBUG
423424
#define dev_dbg(dev, format, arg...) \

0 commit comments

Comments
 (0)