Patchwork [1/3] UBI: improve checking in debugging prints

login
register
mail settings
Submitter Artem Bityutskiy
Date May 23, 2011, 6:26 a.m.
Message ID <1306131989-5391-1-git-send-email-dedekind1@gmail.com>
Download mbox | patch
Permalink /patch/96825/
State Accepted
Commit 3802243a189b0f153acb03f531daf35d40bc38bb
Headers show

Comments

Artem Bityutskiy - May 23, 2011, 6:26 a.m.
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

When debugging is disabled, define debugging prints as if (0) printk() to make
sure that the compiler still the format string in debugging messages even if
debugging is disabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 drivers/mtd/ubi/debug.h |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

Patch

diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index 0b0c288..bdd2c73 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -184,14 +184,31 @@  static inline int ubi_dbg_is_erase_failure(void)
 
 #else
 
-#define ubi_assert(expr)                 ({})
-#define dbg_err(fmt, ...)                ({})
-#define dbg_msg(fmt, ...)                ({})
-#define dbg_gen(fmt, ...)                ({})
-#define dbg_eba(fmt, ...)                ({})
-#define dbg_wl(fmt, ...)                 ({})
-#define dbg_io(fmt, ...)                 ({})
-#define dbg_bld(fmt, ...)                ({})
+/* Use "if (0)" to make compiler check arguments even if debugging is off */
+#define ubi_assert(expr)  do {                                               \
+	if (0) {                                                             \
+		printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \
+		       __func__, __LINE__, current->pid);                    \
+	}                                                                    \
+} while (0)
+
+#define dbg_err(fmt, ...) do {                                               \
+	if (0)                                                               \
+		ubi_err(fmt, ##__VA_ARGS__);                                 \
+} while (0)
+
+#define dbg_msg(fmt, ...) do {                                               \
+	if (0)                                                               \
+		printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n",         \
+		       current->pid, __func__, ##__VA_ARGS__);               \
+} while (0)
+
+#define dbg_gen(fmt, ...)  dbg_msg(fmt, ##__VA_ARGS__)
+#define dbg_eba(fmt, ...)  dbg_msg(fmt, ##__VA_ARGS__)
+#define dbg_wl(fmt, ...)   dbg_msg(fmt, ##__VA_ARGS__)
+#define dbg_io(fmt, ...)   dbg_msg(fmt, ##__VA_ARGS__)
+#define dbg_bld(fmt, ...)  dbg_msg(fmt, ##__VA_ARGS__)
+
 #define ubi_dbg_dump_stack()             ({})
 #define ubi_dbg_dump_ec_hdr(ec_hdr)      ({})
 #define ubi_dbg_dump_vid_hdr(vid_hdr)    ({})