maint: Fix macros with broken 'do/while(0); ' usage
authorEric Blake <eblake@redhat.com>
Fri, 1 Dec 2017 23:24:32 +0000 (17:24 -0600)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 16 Jan 2018 13:54:52 +0000 (14:54 +0100)
The point of writing a macro embedded in a 'do { ... } while (0)'
loop (particularly if the macro has multiple statements or would
otherwise end with an 'if' statement) is so that the macro can be
used as a drop-in statement with the caller supplying the
trailing ';'.  Although our coding style frowns on brace-less 'if':
  if (cond)
    statement;
  else
    something else;
that is the classic case where failure to use do/while(0) wrapping
would cause the 'else' to pair with any embedded 'if' in the macro
rather than the intended outer 'if'.  But conversely, if the macro
includes an embedded ';', then the same brace-less coding style
would now have two statements, making the 'else' a syntax error
rather than pairing with the outer 'if'.  Thus, even though our
coding style with required braces is not impacted, ending a macro
with ';' makes our code harder to port to projects that use
brace-less styles.

The change should have no semantic impact.  I was not able to
fully compile-test all of the changes (as some of them are
examples of the ugly bit-rotting debug print statements that are
completely elided by default, and I didn't want to recompile
with the necessary -D witnesses - cleaning those up is left as a
bite-sized task for another day); I did, however, audit that for
all files touched, all callers of the changed macros DID supply
a trailing ';' at the callsite, and did not appear to be used
as part of a brace-less conditional.

Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20171201232433.25193-7-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
34 files changed:
audio/paaudio.c
hw/adc/stm32f2xx_adc.c
hw/block/m25p80.c
hw/char/cadence_uart.c
hw/char/stm32f2xx_usart.c
hw/display/cg3.c
hw/display/dpcd.c
hw/display/xlnx_dp.c
hw/dma/pl330.c
hw/dma/xlnx-zynq-devcfg.c
hw/dma/xlnx_dpdma.c
hw/i2c/i2c-ddc.c
hw/misc/auxbus.c
hw/misc/macio/mac_dbdma.c
hw/misc/mmio_interface.c
hw/misc/stm32f2xx_syscfg.c
hw/misc/zynq_slcr.c
hw/net/cadence_gem.c
hw/ssi/mss-spi.c
hw/ssi/stm32f2xx_spi.c
hw/ssi/xilinx_spi.c
hw/ssi/xilinx_spips.c
hw/timer/a9gtimer.c
hw/timer/cadence_ttc.c
hw/timer/mss-timer.c
hw/timer/stm32f2xx_timer.c
hw/tpm/tpm_passthrough.c
hw/tpm/tpm_tis.c
migration/rdma.c
target/arm/translate-a64.c
target/s390x/kvm.c
tests/acpi-utils.h
tests/tcg/test-mmap.c
ui/sdl_zoom_template.h

index 65beb6f0104b96538b9445071ab0c3047dbd25ba..2a35e6f82c0bd38d38cac3394ed7ad6e84915dff 100644 (file)
@@ -89,7 +89,7 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x)
             }                                                   \
             goto label;                                         \
         }                                                       \
-    } while (0);
+    } while (0)
 
 #define CHECK_DEAD_GOTO(c, stream, rerror, label)                       \
     do {                                                                \
@@ -107,7 +107,7 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x)
             }                                                           \
             goto label;                                                 \
         }                                                               \
-    } while (0);
+    } while (0)
 
 static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror)
 {
index 90fe9de299326729c2b6c05a81e1a2d9f7d010d1..13f31ad2f743a427a6a9340afeb81f63eee8ba4e 100644 (file)
@@ -37,7 +37,7 @@
     if (STM_ADC_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt, __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index ea142160b31d5a6d48b986fb5260fbf0b85548ae..b49c8e9caa0449f937d9dd796c563b3c141a1b83 100644 (file)
@@ -40,7 +40,7 @@
         fprintf(stderr,  ": %s: ", __func__); \
         fprintf(stderr, ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 /* Fields for FlashPartInfo->flags */
 
index 61434940603627d872b7e2bb03b2c71e413cf3ea..fbdbd463bb5d9141400af53643ce6aed1cd26499 100644 (file)
@@ -33,7 +33,7 @@
 #define DB_PRINT(...) do { \
     fprintf(stderr,  ": %s: ", __func__); \
     fprintf(stderr, ## __VA_ARGS__); \
-    } while (0);
+    } while (0)
 #else
     #define DB_PRINT(...)
 #endif
index 268e4353386f4cf6d478c702acb6f7b61200b943..07b462d4b6396c0fc6bfd66e189822159e88277d 100644 (file)
@@ -34,7 +34,7 @@
     if (STM_USART_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt, __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index e069c4484c239f3020eb30be004c953ef12b2865..cafd9f47ef66466ce391dab31d9d0df9ec4af96d 100644 (file)
@@ -63,7 +63,7 @@
     if (DEBUG_CG3) { \
         printf("CG3: " fmt , ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 #define TYPE_CG3 "cgthree"
 #define CG3(obj) OBJECT_CHECK(CG3State, (obj), TYPE_CG3)
index ce92ff6e2aa8dd5040523bc1cd34c4a5e5112e0e..943002bee5e3fc95a67c3c860c1de8f152486767 100644 (file)
@@ -39,7 +39,7 @@
     if (DEBUG_DPCD) {                                                          \
         qemu_log("dpcd: " fmt, ## __VA_ARGS__);                                \
     }                                                                          \
-} while (0);
+} while (0)
 
 #define DPCD_READABLE_AREA                      0x600
 
index 561f828e7ad47f3abeacd889a34c57e4b16e4144..ead4e1a0e4fa6f5e0e6599c06a74d8e4a2bd1551 100644 (file)
@@ -34,7 +34,7 @@
     if (DEBUG_DP) {                                                            \
         qemu_log("xlnx_dp: " fmt , ## __VA_ARGS__);                            \
     }                                                                          \
-} while (0);
+} while (0)
 
 /*
  * Register offset for DP.
index 32cf8399b8de1ff188ff56e32bff2bfc866038d4..d071049233b101e2922a28c0ed614a9a31a0cc6f 100644 (file)
@@ -29,7 +29,7 @@
     if (PL330_ERR_DEBUG >= lvl) {\
         fprintf(stderr, "PL330: %s:" fmt, __func__, ## args);\
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index 3b10523430bbe62238845545d623a854a15af7ae..12bb2e37168e9c729f540c21d720cdaabb847de5 100644 (file)
@@ -43,7 +43,7 @@
     if (XLNX_ZYNQ_DEVCFG_ERR_DEBUG) { \
         qemu_log("%s: " fmt, __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 REG32(CTRL, 0x00)
     FIELD(CTRL,     FORCE_RST,          31,  1) /* Not supported, wr ignored */
index 8ceb21ddb377b9148bebec6fe19ecccc0dc4d897..077c7da9ccd38a22bb33c853fbed679b7afceef4 100644 (file)
@@ -34,7 +34,7 @@
     if (DEBUG_DPDMA) {                                                         \
         qemu_log("xlnx_dpdma: " fmt , ## __VA_ARGS__);                         \
     }                                                                          \
-} while (0);
+} while (0)
 
 /*
  * Registers offset for DPDMA.
index 6b92e95c73f8afe81cee610706ccfe562d9518de..199dac9e41c1bfb9f3c300eb91b1636e6dc0679c 100644 (file)
@@ -30,7 +30,7 @@
     if (DEBUG_I2CDDC) {                                                        \
         qemu_log("i2c-ddc: " fmt , ## __VA_ARGS__);                            \
     }                                                                          \
-} while (0);
+} while (0)
 
 /* Structure defining a monitor's characteristics in a
  * readable format: this should be passed to build_edid_blob()
index 118274504449c230d7b5243e6d1e6e9fe5493465..b4cacd664b6000c41cd8e5a72dfcc23989486e61 100644 (file)
@@ -40,7 +40,7 @@
     if (DEBUG_AUX) {                                                           \
         qemu_log("aux: " fmt , ## __VA_ARGS__);                                \
     }                                                                          \
-} while (0);
+} while (0)
 
 #define TYPE_AUXTOI2C "aux-to-i2c-bridge"
 #define AUXTOI2C(obj) OBJECT_CHECK(AUXTOI2CState, (obj), TYPE_AUXTOI2C)
index 0eddf2e700951a359e02ab2fa3317e39ca92c645..1b2a69b3efcaee925f6e27bde40c1d2d4a0a9679 100644 (file)
@@ -52,7 +52,7 @@
     if (DEBUG_DBDMA) { \
         printf("DBDMA: " fmt , ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 #define DBDMA_DPRINTFCH(ch, fmt, ...) do { \
     if (DEBUG_DBDMA) { \
@@ -60,7 +60,7 @@
             printf("DBDMA[%02x]: " fmt , (ch)->channel, ## __VA_ARGS__); \
         } \
     } \
-} while (0);
+} while (0)
 
 /*
  */
index 894e9801cb64f213855b6c0b594f2918b9c6ada7..3b0e2039a36e0c566d6701affbee81996488e823 100644 (file)
@@ -39,7 +39,7 @@ static uint64_t mmio_interface_counter;
     if (DEBUG_MMIO_INTERFACE) {                                                \
         qemu_log("mmio_interface: 0x%" PRIX64 ": " fmt, s->id, ## __VA_ARGS__);\
     }                                                                          \
-} while (0);
+} while (0)
 
 static void mmio_interface_init(Object *obj)
 {
index 7c45833d0986d37d4f7c6a87b82e7c4d5bf5d6b6..7f101958621b9c53992db6f8e40a99e2ceccf0f0 100644 (file)
@@ -34,7 +34,7 @@
     if (STM_SYSCFG_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt, __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index 44304d48bef170fb0d6a6b58e92c4cfe198ec8fd..d6bdd027ef5529b3a4df86dd2fa19406a82be200 100644 (file)
@@ -30,7 +30,7 @@
             fprintf(stderr,  ": %s: ", __func__); \
             fprintf(stderr, ## __VA_ARGS__); \
         } \
-    } while (0);
+    } while (0)
 
 #define XILINX_LOCK_KEY 0x767b
 #define XILINX_UNLOCK_KEY 0xdf0d
index 39431875729d479b3ac32454592b0ec994e9eb12..0fa4b0dc4409b27d4b9fbf4e787568139710bfc9 100644 (file)
@@ -34,7 +34,7 @@
 #define DB_PRINT(...) do { \
     fprintf(stderr,  ": %s: ", __func__); \
     fprintf(stderr, ## __VA_ARGS__); \
-    } while (0);
+    } while (0)
 #else
     #define DB_PRINT(...)
 #endif
index d60daba882f159bb102614b822d6785a21ca151f..185e1a3920375cee9c9f5e06cf6778ba5b1ea306 100644 (file)
@@ -35,7 +35,7 @@
     if (MSS_SPI_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt "\n", __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index 26a1b4ddf55782c3119497f56cd0577330a8e43f..69514da9fbb75fa3c790fe451ebb74edd7aea679 100644 (file)
@@ -35,7 +35,7 @@
     if (STM_SPI_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt, __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index 33482f04deba111a64c67013d0db57945f1adcc4..83585bc8b2bdc485fe77e60168fa8991b9c4234e 100644 (file)
@@ -36,7 +36,7 @@
 #define DB_PRINT(...) do { \
     fprintf(stderr,  ": %s: ", __func__); \
     fprintf(stderr, ## __VA_ARGS__); \
-    } while (0);
+    } while (0)
 #else
     #define DB_PRINT(...)
 #endif
index d8187fadd10f623279ca3aedf94356957f4b0eb3..85c5d0cb92a60044c1b673c1d3eba6f1cb0bb137 100644 (file)
@@ -43,7 +43,7 @@
         fprintf(stderr,  ": %s: ", __func__); \
         fprintf(stderr, ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 /* config register */
 #define R_CONFIG            (0x00 / 4)
index ce1dc63911e179af470914396b5effbc612947c8..96d534d8a81c47319e30d8badecf8db87b6618c6 100644 (file)
@@ -37,7 +37,7 @@
         fprintf(stderr,  ": %s: ", __func__); \
         fprintf(stderr, ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(...) DB_PRINT_L(0, ## __VA_ARGS__)
 
index 5e65fdb5a08b824df69253013181fb46302f1830..10056407ab8d75cf55dc78b02d60a8ac9c2d0d9f 100644 (file)
@@ -24,7 +24,7 @@
 #define DB_PRINT(...) do { \
     fprintf(stderr,  ": %s: ", __func__); \
     fprintf(stderr, ## __VA_ARGS__); \
-    } while (0);
+    } while (0)
 #else
     #define DB_PRINT(...)
 #endif
index 60f1213a3b2ad3fdf90fe5c6a1065f7cfce23eaa..4f814572e2a05057fd6429b8d73252fe0c0c24de 100644 (file)
@@ -36,7 +36,7 @@
     if (MSS_TIMER_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt "\n", __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index e5f5e14a90b1c243729583427b2479bdaaacc0ab..58fc7b1188e6fc96b717d2dcf45907268d6d08bc 100644 (file)
@@ -34,7 +34,7 @@
     if (STM_TIMER_ERR_DEBUG >= lvl) { \
         qemu_log("%s: " fmt, __func__, ## args); \
     } \
-} while (0);
+} while (0)
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
index 149fae63e668fdcea330f51530045b903136fb2d..29142f38bb4a0ceaf132ed0289b1ddd3938e984a 100644 (file)
@@ -38,7 +38,7 @@
     if (DEBUG_TPM) { \
         fprintf(stderr, fmt, ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 #define TYPE_TPM_PASSTHROUGH "tpm-passthrough"
 #define TPM_PASSTHROUGH(obj) \
index 561384cd8677a5851b0621075005ba6d6d6eced7..8b5eb01a2c3e94825286ce3e7a3f137392955bb7 100644 (file)
@@ -90,7 +90,7 @@ typedef struct TPMState {
     if (DEBUG_TIS) { \
         printf(fmt, ## __VA_ARGS__); \
     } \
-} while (0);
+} while (0)
 
 /* tis registers */
 #define TPM_TIS_REG_ACCESS                0x00
index ca56594328b64dbaedc49f73b1a33980f7b22c7e..9d5a42401174753fbdc6b9b47b60436106e78143 100644 (file)
@@ -88,7 +88,7 @@ static uint32_t known_capabilities = RDMA_CAPABILITY_PIN_ALL;
             } \
             return rdma->error_state; \
         } \
-    } while (0);
+    } while (0)
 
 /*
  * A work request ID is 64-bits and we split up these bits
index ba94f7d0456a9ae43c7c1c4f16bafa3f9196aea7..cba5587812b478d23cbcbc87379da7bc799bbb53 100644 (file)
@@ -400,7 +400,7 @@ static void unallocated_encoding(DisasContext *s)
                       "at pc=%016" PRIx64 "\n",                          \
                       __FILE__, __LINE__, insn, s->pc - 4);              \
         unallocated_encoding(s);                                         \
-    } while (0);
+    } while (0)
 
 static void init_tmp_a64_array(DisasContext *s)
 {
index 9b8b59f2a24f80dfa06435c7e9c99d2f0c4097ac..6a18a413b49c79434dc89e57370f1dff4b4312cb 100644 (file)
@@ -58,7 +58,7 @@
     if (DEBUG_KVM) {                          \
         fprintf(stderr, fmt, ## __VA_ARGS__); \
     }                                         \
-} while (0);
+} while (0)
 
 #define kvm_vm_check_mem_attr(s, attr) \
     kvm_vm_check_attr(s, KVM_S390_VM_MEM_CTRL, attr)
index d5ca5b6238316f19c81f60f19b962ff26677d841..ac52abd0ddb107a50b85829f1dd9d7a54ab06612 100644 (file)
@@ -32,7 +32,7 @@ typedef struct {
     do {                                        \
         memread(addr, &field, sizeof(field));   \
         addr += sizeof(field);                  \
-    } while (0);
+    } while (0)
 
 #define ACPI_READ_ARRAY_PTR(arr, length, addr)  \
     do {                                        \
@@ -40,7 +40,7 @@ typedef struct {
         for (idx = 0; idx < length; ++idx) {    \
             ACPI_READ_FIELD(arr[idx], addr);    \
         }                                       \
-    } while (0);
+    } while (0)
 
 #define ACPI_READ_ARRAY(arr, addr)                               \
     ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr)
@@ -56,7 +56,7 @@ typedef struct {
         ACPI_READ_FIELD((table)->oem_revision, addr);            \
         ACPI_READ_ARRAY((table)->asl_compiler_id, addr);         \
         ACPI_READ_FIELD((table)->asl_compiler_revision, addr);   \
-    } while (0);
+    } while (0)
 
 #define ACPI_ASSERT_CMP(actual, expected) do { \
     char ACPI_ASSERT_CMP_str[5] = {}; \
@@ -77,7 +77,7 @@ typedef struct {
         ACPI_READ_FIELD((field).bit_offset, addr);   \
         ACPI_READ_FIELD((field).access_width, addr); \
         ACPI_READ_FIELD((field).address, addr);      \
-    } while (0);
+    } while (0)
 
 
 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
index 3982fa2c72569bbd4d124cd245ba7859e980faaf..cdefadfa4c66a358dee45fac8a35493cfa50a7b4 100644 (file)
@@ -39,7 +39,7 @@ do                                                             \
     fprintf (stderr, "FAILED at %s:%d\n", __FILE__, __LINE__); \
     exit (EXIT_FAILURE);                                       \
   }                                                            \
-} while (0);
+} while (0)
 
 unsigned char *dummybuf;
 static unsigned int pagesize;
index 3bb508b51e48f4fc2bfd1c4d8505499f521b12ca..6a424adfb447bc924d408d6a61490f7161190e3c 100644 (file)
 #define setRed(r, pcolor) do { \
     *pcolor = ((*pcolor) & (~(dpf->Rmask))) + \
               (((r) & (dpf->Rmask >> dpf->Rshift)) << dpf->Rshift); \
-} while (0);
+} while (0)
 
 #define setGreen(g, pcolor) do { \
     *pcolor = ((*pcolor) & (~(dpf->Gmask))) + \
               (((g) & (dpf->Gmask >> dpf->Gshift)) << dpf->Gshift); \
-} while (0);
+} while (0)
 
 #define setBlue(b, pcolor) do { \
     *pcolor = ((*pcolor) & (~(dpf->Bmask))) + \
               (((b) & (dpf->Bmask >> dpf->Bshift)) << dpf->Bshift); \
-} while (0);
+} while (0)
 
 #define setAlpha(a, pcolor) do { \
     *pcolor = ((*pcolor) & (~(dpf->Amask))) + \
               (((a) & (dpf->Amask >> dpf->Ashift)) << dpf->Ashift); \
-} while (0);
+} while (0)
 
 static void glue(sdl_zoom_rgb, BPP)(SDL_Surface *src, SDL_Surface *dst, int smooth,
                                    SDL_Rect *dst_rect)