All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 12/43] sd: made printf always compile in debug output
@ 2017-04-01 13:47 Danil Antonov
  0 siblings, 0 replies; only message in thread
From: Danil Antonov @ 2017-04-01 13:47 UTC (permalink / raw)
  To: qemu-devel, peter.maydell

>From 78c7cc133ba566b13afe6e9924e174b6d081e393 Mon Sep 17 00:00:00 2001
From: Danil Antonov <g.danil.anto@gmail.com>
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 <g.danil.anto@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-01 13:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01 13:47 [Qemu-devel] [PATCH 12/43] sd: made printf always compile in debug output Danil Antonov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.