[PATCH 4/5] driver: rewrite dev_printf as a function

Sascha Hauer s.hauer at pengutronix.de
Tue Sep 11 09:31:52 EDT 2012


Printing device context normally should be "driver instance:",
but instead we printed the device name twice. This patch fixes
this and as a bonus makes the binary a bit smaller. Instead of
a '@' between driver and instance this function now prints a
whitespace which is a bit more like Linux.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/base/driver.c |   19 +++++++++++++++++++
 include/driver.h      |    6 +++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 6cd4286..47d3803 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -313,6 +313,25 @@ const char *dev_id(const struct device_d *dev)
 	return buf;
 }
 
+int dev_printf(const struct device_d *dev, const char *format, ...)
+{
+	va_list args;
+	int ret = 0;
+
+	if (dev->driver && dev->driver->name)
+		ret += printf("%s ", dev->driver->name);
+
+	ret += printf("%s: ", dev_name(dev));
+
+	va_start(args, format);
+
+	ret += vprintf(format, args);
+
+	va_end(args);
+
+	return ret;
+}
+
 void devices_shutdown(void)
 {
 	struct device_d *dev;
diff --git a/include/driver.h b/include/driver.h
index 0fecc7a..c74f245 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -333,9 +333,9 @@ static inline int dev_close_default(struct device_d *dev, struct filep *f)
 
 /* debugging and troubleshooting/diagnostic helpers. */
 
-#define dev_printf(dev, format, arg...)	\
-	printf("%s@%s: " format , (dev)->name , \
-	       dev_name(dev) , ## arg)
+int dev_printf(const struct device_d *dev, const char *format, ...)
+	__attribute__ ((format(__printf__, 2, 3)));
+
 
 #define dev_emerg(dev, format, arg...)		\
 	dev_printf((dev) , format , ## arg)
-- 
1.7.10.4




More information about the barebox mailing list