qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

maint: Fix macros with broken 'do/while(0); ' usage

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>

authored by

Eric Blake and committed by
Paolo Bonzini
2562755e 241187c1

+42 -42
+2 -2
audio/paaudio.c
··· 89 89 } \ 90 90 goto label; \ 91 91 } \ 92 - } while (0); 92 + } while (0) 93 93 94 94 #define CHECK_DEAD_GOTO(c, stream, rerror, label) \ 95 95 do { \ ··· 107 107 } \ 108 108 goto label; \ 109 109 } \ 110 - } while (0); 110 + } while (0) 111 111 112 112 static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror) 113 113 {
+1 -1
hw/adc/stm32f2xx_adc.c
··· 37 37 if (STM_ADC_ERR_DEBUG >= lvl) { \ 38 38 qemu_log("%s: " fmt, __func__, ## args); \ 39 39 } \ 40 - } while (0); 40 + } while (0) 41 41 42 42 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 43 43
+1 -1
hw/block/m25p80.c
··· 40 40 fprintf(stderr, ": %s: ", __func__); \ 41 41 fprintf(stderr, ## __VA_ARGS__); \ 42 42 } \ 43 - } while (0); 43 + } while (0) 44 44 45 45 /* Fields for FlashPartInfo->flags */ 46 46
+1 -1
hw/char/cadence_uart.c
··· 33 33 #define DB_PRINT(...) do { \ 34 34 fprintf(stderr, ": %s: ", __func__); \ 35 35 fprintf(stderr, ## __VA_ARGS__); \ 36 - } while (0); 36 + } while (0) 37 37 #else 38 38 #define DB_PRINT(...) 39 39 #endif
+1 -1
hw/char/stm32f2xx_usart.c
··· 34 34 if (STM_USART_ERR_DEBUG >= lvl) { \ 35 35 qemu_log("%s: " fmt, __func__, ## args); \ 36 36 } \ 37 - } while (0); 37 + } while (0) 38 38 39 39 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 40 40
+1 -1
hw/display/cg3.c
··· 63 63 if (DEBUG_CG3) { \ 64 64 printf("CG3: " fmt , ## __VA_ARGS__); \ 65 65 } \ 66 - } while (0); 66 + } while (0) 67 67 68 68 #define TYPE_CG3 "cgthree" 69 69 #define CG3(obj) OBJECT_CHECK(CG3State, (obj), TYPE_CG3)
+1 -1
hw/display/dpcd.c
··· 39 39 if (DEBUG_DPCD) { \ 40 40 qemu_log("dpcd: " fmt, ## __VA_ARGS__); \ 41 41 } \ 42 - } while (0); 42 + } while (0) 43 43 44 44 #define DPCD_READABLE_AREA 0x600 45 45
+1 -1
hw/display/xlnx_dp.c
··· 34 34 if (DEBUG_DP) { \ 35 35 qemu_log("xlnx_dp: " fmt , ## __VA_ARGS__); \ 36 36 } \ 37 - } while (0); 37 + } while (0) 38 38 39 39 /* 40 40 * Register offset for DP.
+1 -1
hw/dma/pl330.c
··· 29 29 if (PL330_ERR_DEBUG >= lvl) {\ 30 30 fprintf(stderr, "PL330: %s:" fmt, __func__, ## args);\ 31 31 } \ 32 - } while (0); 32 + } while (0) 33 33 34 34 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 35 35
+1 -1
hw/dma/xlnx-zynq-devcfg.c
··· 43 43 if (XLNX_ZYNQ_DEVCFG_ERR_DEBUG) { \ 44 44 qemu_log("%s: " fmt, __func__, ## args); \ 45 45 } \ 46 - } while (0); 46 + } while (0) 47 47 48 48 REG32(CTRL, 0x00) 49 49 FIELD(CTRL, FORCE_RST, 31, 1) /* Not supported, wr ignored */
+1 -1
hw/dma/xlnx_dpdma.c
··· 34 34 if (DEBUG_DPDMA) { \ 35 35 qemu_log("xlnx_dpdma: " fmt , ## __VA_ARGS__); \ 36 36 } \ 37 - } while (0); 37 + } while (0) 38 38 39 39 /* 40 40 * Registers offset for DPDMA.
+1 -1
hw/i2c/i2c-ddc.c
··· 30 30 if (DEBUG_I2CDDC) { \ 31 31 qemu_log("i2c-ddc: " fmt , ## __VA_ARGS__); \ 32 32 } \ 33 - } while (0); 33 + } while (0) 34 34 35 35 /* Structure defining a monitor's characteristics in a 36 36 * readable format: this should be passed to build_edid_blob()
+1 -1
hw/misc/auxbus.c
··· 40 40 if (DEBUG_AUX) { \ 41 41 qemu_log("aux: " fmt , ## __VA_ARGS__); \ 42 42 } \ 43 - } while (0); 43 + } while (0) 44 44 45 45 #define TYPE_AUXTOI2C "aux-to-i2c-bridge" 46 46 #define AUXTOI2C(obj) OBJECT_CHECK(AUXTOI2CState, (obj), TYPE_AUXTOI2C)
+2 -2
hw/misc/macio/mac_dbdma.c
··· 52 52 if (DEBUG_DBDMA) { \ 53 53 printf("DBDMA: " fmt , ## __VA_ARGS__); \ 54 54 } \ 55 - } while (0); 55 + } while (0) 56 56 57 57 #define DBDMA_DPRINTFCH(ch, fmt, ...) do { \ 58 58 if (DEBUG_DBDMA) { \ ··· 60 60 printf("DBDMA[%02x]: " fmt , (ch)->channel, ## __VA_ARGS__); \ 61 61 } \ 62 62 } \ 63 - } while (0); 63 + } while (0) 64 64 65 65 /* 66 66 */
+1 -1
hw/misc/mmio_interface.c
··· 39 39 if (DEBUG_MMIO_INTERFACE) { \ 40 40 qemu_log("mmio_interface: 0x%" PRIX64 ": " fmt, s->id, ## __VA_ARGS__);\ 41 41 } \ 42 - } while (0); 42 + } while (0) 43 43 44 44 static void mmio_interface_init(Object *obj) 45 45 {
+1 -1
hw/misc/stm32f2xx_syscfg.c
··· 34 34 if (STM_SYSCFG_ERR_DEBUG >= lvl) { \ 35 35 qemu_log("%s: " fmt, __func__, ## args); \ 36 36 } \ 37 - } while (0); 37 + } while (0) 38 38 39 39 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 40 40
+1 -1
hw/misc/zynq_slcr.c
··· 30 30 fprintf(stderr, ": %s: ", __func__); \ 31 31 fprintf(stderr, ## __VA_ARGS__); \ 32 32 } \ 33 - } while (0); 33 + } while (0) 34 34 35 35 #define XILINX_LOCK_KEY 0x767b 36 36 #define XILINX_UNLOCK_KEY 0xdf0d
+1 -1
hw/net/cadence_gem.c
··· 34 34 #define DB_PRINT(...) do { \ 35 35 fprintf(stderr, ": %s: ", __func__); \ 36 36 fprintf(stderr, ## __VA_ARGS__); \ 37 - } while (0); 37 + } while (0) 38 38 #else 39 39 #define DB_PRINT(...) 40 40 #endif
+1 -1
hw/ssi/mss-spi.c
··· 35 35 if (MSS_SPI_ERR_DEBUG >= lvl) { \ 36 36 qemu_log("%s: " fmt "\n", __func__, ## args); \ 37 37 } \ 38 - } while (0); 38 + } while (0) 39 39 40 40 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 41 41
+1 -1
hw/ssi/stm32f2xx_spi.c
··· 35 35 if (STM_SPI_ERR_DEBUG >= lvl) { \ 36 36 qemu_log("%s: " fmt, __func__, ## args); \ 37 37 } \ 38 - } while (0); 38 + } while (0) 39 39 40 40 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 41 41
+1 -1
hw/ssi/xilinx_spi.c
··· 36 36 #define DB_PRINT(...) do { \ 37 37 fprintf(stderr, ": %s: ", __func__); \ 38 38 fprintf(stderr, ## __VA_ARGS__); \ 39 - } while (0); 39 + } while (0) 40 40 #else 41 41 #define DB_PRINT(...) 42 42 #endif
+1 -1
hw/ssi/xilinx_spips.c
··· 43 43 fprintf(stderr, ": %s: ", __func__); \ 44 44 fprintf(stderr, ## __VA_ARGS__); \ 45 45 } \ 46 - } while (0); 46 + } while (0) 47 47 48 48 /* config register */ 49 49 #define R_CONFIG (0x00 / 4)
+1 -1
hw/timer/a9gtimer.c
··· 37 37 fprintf(stderr, ": %s: ", __func__); \ 38 38 fprintf(stderr, ## __VA_ARGS__); \ 39 39 } \ 40 - } while (0); 40 + } while (0) 41 41 42 42 #define DB_PRINT(...) DB_PRINT_L(0, ## __VA_ARGS__) 43 43
+1 -1
hw/timer/cadence_ttc.c
··· 24 24 #define DB_PRINT(...) do { \ 25 25 fprintf(stderr, ": %s: ", __func__); \ 26 26 fprintf(stderr, ## __VA_ARGS__); \ 27 - } while (0); 27 + } while (0) 28 28 #else 29 29 #define DB_PRINT(...) 30 30 #endif
+1 -1
hw/timer/mss-timer.c
··· 36 36 if (MSS_TIMER_ERR_DEBUG >= lvl) { \ 37 37 qemu_log("%s: " fmt "\n", __func__, ## args); \ 38 38 } \ 39 - } while (0); 39 + } while (0) 40 40 41 41 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 42 42
+1 -1
hw/timer/stm32f2xx_timer.c
··· 34 34 if (STM_TIMER_ERR_DEBUG >= lvl) { \ 35 35 qemu_log("%s: " fmt, __func__, ## args); \ 36 36 } \ 37 - } while (0); 37 + } while (0) 38 38 39 39 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args) 40 40
+1 -1
hw/tpm/tpm_passthrough.c
··· 38 38 if (DEBUG_TPM) { \ 39 39 fprintf(stderr, fmt, ## __VA_ARGS__); \ 40 40 } \ 41 - } while (0); 41 + } while (0) 42 42 43 43 #define TYPE_TPM_PASSTHROUGH "tpm-passthrough" 44 44 #define TPM_PASSTHROUGH(obj) \
+1 -1
hw/tpm/tpm_tis.c
··· 90 90 if (DEBUG_TIS) { \ 91 91 printf(fmt, ## __VA_ARGS__); \ 92 92 } \ 93 - } while (0); 93 + } while (0) 94 94 95 95 /* tis registers */ 96 96 #define TPM_TIS_REG_ACCESS 0x00
+1 -1
migration/rdma.c
··· 88 88 } \ 89 89 return rdma->error_state; \ 90 90 } \ 91 - } while (0); 91 + } while (0) 92 92 93 93 /* 94 94 * A work request ID is 64-bits and we split up these bits
+1 -1
target/arm/translate-a64.c
··· 400 400 "at pc=%016" PRIx64 "\n", \ 401 401 __FILE__, __LINE__, insn, s->pc - 4); \ 402 402 unallocated_encoding(s); \ 403 - } while (0); 403 + } while (0) 404 404 405 405 static void init_tmp_a64_array(DisasContext *s) 406 406 {
+1 -1
target/s390x/kvm.c
··· 58 58 if (DEBUG_KVM) { \ 59 59 fprintf(stderr, fmt, ## __VA_ARGS__); \ 60 60 } \ 61 - } while (0); 61 + } while (0) 62 62 63 63 #define kvm_vm_check_mem_attr(s, attr) \ 64 64 kvm_vm_check_attr(s, KVM_S390_VM_MEM_CTRL, attr)
+4 -4
tests/acpi-utils.h
··· 32 32 do { \ 33 33 memread(addr, &field, sizeof(field)); \ 34 34 addr += sizeof(field); \ 35 - } while (0); 35 + } while (0) 36 36 37 37 #define ACPI_READ_ARRAY_PTR(arr, length, addr) \ 38 38 do { \ ··· 40 40 for (idx = 0; idx < length; ++idx) { \ 41 41 ACPI_READ_FIELD(arr[idx], addr); \ 42 42 } \ 43 - } while (0); 43 + } while (0) 44 44 45 45 #define ACPI_READ_ARRAY(arr, addr) \ 46 46 ACPI_READ_ARRAY_PTR(arr, sizeof(arr) / sizeof(arr[0]), addr) ··· 56 56 ACPI_READ_FIELD((table)->oem_revision, addr); \ 57 57 ACPI_READ_ARRAY((table)->asl_compiler_id, addr); \ 58 58 ACPI_READ_FIELD((table)->asl_compiler_revision, addr); \ 59 - } while (0); 59 + } while (0) 60 60 61 61 #define ACPI_ASSERT_CMP(actual, expected) do { \ 62 62 char ACPI_ASSERT_CMP_str[5] = {}; \ ··· 77 77 ACPI_READ_FIELD((field).bit_offset, addr); \ 78 78 ACPI_READ_FIELD((field).access_width, addr); \ 79 79 ACPI_READ_FIELD((field).address, addr); \ 80 - } while (0); 80 + } while (0) 81 81 82 82 83 83 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
+1 -1
tests/tcg/test-mmap.c
··· 39 39 fprintf (stderr, "FAILED at %s:%d\n", __FILE__, __LINE__); \ 40 40 exit (EXIT_FAILURE); \ 41 41 } \ 42 - } while (0); 42 + } while (0) 43 43 44 44 unsigned char *dummybuf; 45 45 static unsigned int pagesize;
+4 -4
ui/sdl_zoom_template.h
··· 34 34 #define setRed(r, pcolor) do { \ 35 35 *pcolor = ((*pcolor) & (~(dpf->Rmask))) + \ 36 36 (((r) & (dpf->Rmask >> dpf->Rshift)) << dpf->Rshift); \ 37 - } while (0); 37 + } while (0) 38 38 39 39 #define setGreen(g, pcolor) do { \ 40 40 *pcolor = ((*pcolor) & (~(dpf->Gmask))) + \ 41 41 (((g) & (dpf->Gmask >> dpf->Gshift)) << dpf->Gshift); \ 42 - } while (0); 42 + } while (0) 43 43 44 44 #define setBlue(b, pcolor) do { \ 45 45 *pcolor = ((*pcolor) & (~(dpf->Bmask))) + \ 46 46 (((b) & (dpf->Bmask >> dpf->Bshift)) << dpf->Bshift); \ 47 - } while (0); 47 + } while (0) 48 48 49 49 #define setAlpha(a, pcolor) do { \ 50 50 *pcolor = ((*pcolor) & (~(dpf->Amask))) + \ 51 51 (((a) & (dpf->Amask >> dpf->Ashift)) << dpf->Ashift); \ 52 - } while (0); 52 + } while (0) 53 53 54 54 static void glue(sdl_zoom_rgb, BPP)(SDL_Surface *src, SDL_Surface *dst, int smooth, 55 55 SDL_Rect *dst_rect)