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

>From 48b18f304de1761128e8cccbb517ddad4346c824 Mon Sep 17 00:00:00 2001
From: Danil Antonov <g.danil.anto@gmail.com>
Date: Wed, 29 Mar 2017 12:26:43 +0300
Subject: [PATCH 11/43] scsi: 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/scsi/lsi53c895a.c   | 26 ++++++++++++++++----------
 hw/scsi/scsi-disk.c    | 17 ++++++++++-------
 hw/scsi/scsi-generic.c | 17 +++++++++--------
 3 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 595c260..379db4b 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -24,16 +24,22 @@
 //#define DEBUG_LSI
 //#define DEBUG_LSI_REG

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

 static const char *names[] = {
     "SCNTL0", "SCNTL1", "SCNTL2", "SCNTL3", "SCID", "SXFER", "SDID",
"GPREG",
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index a53f058..33213df 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -19,14 +19,17 @@
  * the host adapter emulator.
  */

-//#define DEBUG_SCSI

-#ifdef DEBUG_SCSI
-#define DPRINTF(fmt, ...) \
-do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
-#endif
+#ifndef DEBUG_SCSI
+#define DEBUG_SCSI 0
+#endif
+
+#define DPRINTF(fmt, ...) do {                               \
+    if (DEBUG_SCSI) {                                        \
+        fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); \
+    }                                                        \
+} while (0);
+

 #include "qemu/osdep.h"
 #include "qapi/error.h"
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index a55ff87..dcd3c08 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -21,14 +21,15 @@

 #ifdef __linux__

-//#define DEBUG_SCSI
-
-#ifdef DEBUG_SCSI
-#define DPRINTF(fmt, ...) \
-do { printf("scsi-generic: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
-#endif
+#ifndef DEBUG_SCSI
+#define DEBUG_SCSI 0
+#endif
+
+#define DPRINTF(fmt, ...) do {                                  \
+    if (DEBUG_SCSI) {                                           \
+        fprintf(stderr, "scsi-generic: " fmt , ## __VA_ARGS__); \
+    }                                                           \
+} while (0);

 #define BADF(fmt, ...) \
 do { fprintf(stderr, "scsi-generic: " fmt , ## __VA_ARGS__); } while (0)
-- 
2.8.0.rc3

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

only message in thread, other threads:[~2017-04-01 13:46 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:46 [Qemu-devel] [PATCH 11/43] scsi: 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.