[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 33/43] i2c: made printf always compile in debug outp
From: |
Danil Antonov |
Subject: |
[Qemu-devel] [PATCH 33/43] i2c: made printf always compile in debug output |
Date: |
Sat, 1 Apr 2017 17:03:58 +0300 |
>From 0372d38e66070fefc5f65573dc7fe7bce4cbb9fd Mon Sep 17 00:00:00 2001
From: Danil Antonov <address@hidden>
Date: Wed, 29 Mar 2017 12:40:31 +0300
Subject: [PATCH 33/43] i2c: 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/i2c/bitbang_i2c.c | 16 ++++++++++------
hw/i2c/pm_smbus.c | 15 ++++++++++-----
hw/i2c/smbus.c | 28 ++++++++++++++++++----------
3 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/hw/i2c/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c
index 8be88ee..55a5f85 100644
--- a/hw/i2c/bitbang_i2c.c
+++ b/hw/i2c/bitbang_i2c.c
@@ -16,12 +16,16 @@
//#define DEBUG_BITBANG_I2C
-#ifdef DEBUG_BITBANG_I2C
-#define DPRINTF(fmt, ...) \
-do { printf("bitbang_i2c: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
-#endif
+#ifndef DEBUG_BITBANG_I2C
+#define DEBUG_BITBANG_I2C 0
+#endif
+
+#define DPRINTF(fmt, ...) \
+ do { \
+ if (DEBUG_BITBANG_I2C) { \
+ fprintf(stderr, "bitbang_i2c: " fmt, ## __VA_ARGS__); \
+ } \
+ } while (0)
typedef enum bitbang_i2c_state {
STOPPED = 0,
diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c
index 6fc3923..b36a460 100644
--- a/hw/i2c/pm_smbus.c
+++ b/hw/i2c/pm_smbus.c
@@ -47,11 +47,16 @@
//#define DEBUG
-#ifdef DEBUG
-# define SMBUS_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
-#else
-# define SMBUS_DPRINTF(format, ...) do { } while (0)
-#endif
+#ifndef DEBUG
+#define DEBUG 0
+#endif
+
+#define SMBUS_DPRINTF(fmt, ...) \
+ do { \
+ if (DEBUG) { \
+ fprintf(stderr, fmt, ## __VA_ARGS__); \
+ } \
+ } while (0)
static void smb_transaction(PMSMBus *s)
diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 2d1b79a..a81445b 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -16,16 +16,24 @@
//#define DEBUG_SMBUS 1
-#ifdef DEBUG_SMBUS
-#define DPRINTF(fmt, ...) \
-do { printf("smbus(%02x): " fmt , dev->i2c.address, ## __VA_ARGS__); }
while (0)
-#define BADF(fmt, ...) \
-do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__); exit(1);}
while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
-#define BADF(fmt, ...) \
-do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__);} while (0)
-#endif
+#ifndef DEBUG_SMBUS
+#define DEBUG_SMBUS 0
+#endif
+
+#define DPRINTF(fmt,
...) \
+ do
{
\
+ if (DEBUG_SMBUS)
{ \
+ fprintf(stderr, "smbus(%02x): " fmt , dev->i2c.address, ##
__VA_ARGS__); \
+
}
\
+ } while (0)
+
+#define BADF(fmt, ...) \
+ do { \
+ fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__); \
+ if (DEBUG_SMBUS) { \
+ exit(1); \
+ } \
+ } while (0)
enum {
SMBUS_IDLE,
--
2.8.0.rc3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] [PATCH 33/43] i2c: made printf always compile in debug output,
Danil Antonov <=