From 2562755ee78983930d0662fa4d3bc5e2ac166350 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 1 Dec 2017 17:24:32 -0600 Subject: 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 Acked-by: Cornelia Huck Reviewed-by: Michael S. Tsirkin Acked-by: Dr. David Alan Gilbert Message-Id: <20171201232433.25193-7-eblake@redhat.com> Reviewed-by: Juan Quintela Signed-off-by: Paolo Bonzini --- hw/tpm/tpm_passthrough.c | 2 +- hw/tpm/tpm_tis.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'hw/tpm') diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 149fae6..29142f3 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -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) \ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 561384c..8b5eb01 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -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 -- cgit v1.1