qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 12/43] sd: made printf always compile in debug outpu


From: Danil Antonov
Subject: [Qemu-devel] [PATCH 12/43] sd: made printf always compile in debug output
Date: Sat, 1 Apr 2017 16:47:18 +0300

>From 78c7cc133ba566b13afe6e9924e174b6d081e393 Mon Sep 17 00:00:00 2001
From: Danil Antonov <address@hidden>
Date: Wed, 29 Mar 2017 12:27:24 +0300
Subject: [PATCH 12/43] sd: made printf always compile in debug output

Wrapped printf calls inside debug macros (DPRINTF) in `if` statement.
This will ensure that printf function will always compile even if debug
output is turned off and, in turn, will prevent bitrot of the format
strings.

Signed-off-by: Danil Antonov <address@hidden>
---
 hw/sd/pl181.c  | 16 ++++++++++------
 hw/sd/sd.c     | 14 +++++++++-----
 hw/sd/ssi-sd.c | 27 +++++++++++++++++----------
 3 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c
index 82c63a4..e4d350f 100644
--- a/hw/sd/pl181.c
+++ b/hw/sd/pl181.c
@@ -16,14 +16,18 @@
 #include "qapi/error.h"

 //#define DEBUG_PL181 1
-
-#ifdef DEBUG_PL181
-#define DPRINTF(fmt, ...) \
-do { printf("pl181: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
+//
+#ifndef DEBUG_PL181
+#define DEBUG_PL181 0
 #endif

+#define DPRINTF(fmt, ...)                                   \
+    do {                                                    \
+        if (DEBUG_PL181) {                                  \
+            fprintf(stderr, "pl181: " fmt, ## __VA_ARGS__); \
+        }                                                   \
+    } while (0)
+
 #define PL181_FIFO_LEN 16

 #define TYPE_PL181 "pl181"
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index ba47bff..f2cd369 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -43,13 +43,17 @@

 //#define DEBUG_SD 1

-#ifdef DEBUG_SD
-#define DPRINTF(fmt, ...) \
-do { fprintf(stderr, "SD: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
+#ifndef DEBUG_SD
+#define DEBUG_SD 0
 #endif

+#define DPRINTF(fmt, ...)                                \
+    do {                                                 \
+        if (DEBUG_SD) {                                  \
+            fprintf(stderr, "SD: " fmt, ## __VA_ARGS__); \
+        }                                                \
+    } while (0)
+
 #define ACMD41_ENQUIRY_MASK     0x00ffffff
 #define OCR_POWER_UP            0x80000000
 #define OCR_POWER_DELAY_NS      500000 /* 0.5ms */
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 24001dc..c8168ae 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -18,18 +18,25 @@
 #include "qapi/error.h"

 //#define DEBUG_SSI_SD 1
-
-#ifdef DEBUG_SSI_SD
-#define DPRINTF(fmt, ...) \
-do { printf("ssi_sd: " fmt , ## __VA_ARGS__); } while (0)
-#define BADF(fmt, ...) \
-do { fprintf(stderr, "ssi_sd: error: " fmt , ## __VA_ARGS__); exit(1);}
while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
-#define BADF(fmt, ...) \
-do { fprintf(stderr, "ssi_sd: error: " fmt , ## __VA_ARGS__);} while (0)
+#ifndef DEBUG_SSI_SD
+#define DEBUG_SSI_SD 0
 #endif

+#define DPRINTF(fmt, ...)                                    \
+    do {                                                     \
+        if (DEBUG_SSI_SD) {                                  \
+            fprintf(stderr, "ssi_sd: " fmt, ## __VA_ARGS__); \
+        }                                                    \
+    } while (0)
+
+#define BADF(fmt, ...)                                          \
+    do {                                                        \
+        fprintf(stderr, "ssi_sd: error: " fmt, ## __VA_ARGS__); \
+        if (DEBUG_SSI_SD) {                                     \
+            exit(1);                                            \
+        }                                                       \
+    } while (0)
+
 typedef enum {
     SSI_SD_CMD = 0,
     SSI_SD_CMDARG,
-- 
2.8.0.rc3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]