Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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 <matthew@wil.cx>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
3e95637a e9a7d305

+18 -1
+16
drivers/base/core.c
··· 29 29 * sysfs bindings for devices. 30 30 */ 31 31 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 + 32 48 #define to_dev(obj) container_of(obj, struct device, kobj) 33 49 #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) 34 50
+2 -1
include/linux/device.h
··· 416 416 extern void firmware_unregister(struct subsystem *); 417 417 418 418 /* debugging and troubleshooting/diagnostic helpers. */ 419 + extern const char *dev_driver_string(struct device *dev); 419 420 #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) 421 422 422 423 #ifdef DEBUG 423 424 #define dev_dbg(dev, format, arg...) \