]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Add pr_fmt() macro
authorThierry Reding <treding@nvidia.com>
Thu, 13 Nov 2014 01:26:50 +0000 (18:26 -0700)
committerTom Rini <trini@ti.com>
Sun, 23 Nov 2014 11:49:02 +0000 (06:49 -0500)
This macro can be overridden in source files (before including common.h)
and can be used to specify a prefix for debug and error messages. An
example of how to use this is shown below:

#define pr_fmt(fmt) "foo: " fmt

#include <common.h>

...
debug("bar");

The resulting message will read:

foo: bar

Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
include/common.h

index ce0a7343f4e402683459b244580ee3b713cf2097..f1ab2cf5f469a354d1f808212987fa72dc1699a0 100644 (file)
@@ -97,15 +97,19 @@ typedef volatile unsigned char      vu_char;
 #define _DEBUG 0
 #endif
 
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
 /*
  * Output a debug text when condition "cond" is met. The "cond" should be
  * computed by a preprocessor in the best case, allowing for the best
  * optimization.
  */
-#define debug_cond(cond, fmt, args...)         \
-       do {                                    \
-               if (cond)                       \
-                       printf(fmt, ##args);    \
+#define debug_cond(cond, fmt, args...)                 \
+       do {                                            \
+               if (cond)                               \
+                       printf(pr_fmt(fmt), ##args);    \
        } while (0)
 
 #define debug(fmt, args...)                    \
@@ -127,7 +131,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
                __assert_fail(#x, __FILE__, __LINE__, __func__); })
 
 #define error(fmt, args...) do {                                       \
-               printf("ERROR: " fmt "\nat %s:%d/%s()\n",               \
+               printf("ERROR: " pr_fmt(fmt) "\nat %s:%d/%s()\n",       \
                        ##args, __FILE__, __LINE__, __func__);          \
 } while (0)