From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 4/3] checkpatch: Enforce proper do/while (0) style
Date: Thu, 30 Nov 2017 11:00:58 -0600 [thread overview]
Message-ID: <04c922b4-7287-61e7-1afc-4e64f39c52a5@redhat.com> (raw)
In-Reply-To: <20171130140154.11161-1-eblake@redhat.com>
On 11/30/2017 08:01 AM, Eric Blake wrote:
> while (0) is only idiomatic in a macro definition, where the caller
> will be supplying the trailing ';'. Warn if the macro has a duplicate.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> scripts/checkpatch.pl | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 34df753571..acb66bff34 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1622,6 +1622,11 @@ sub process {
> }
> }
>
> +# 'while (0);' is odd; only macros should use while (0), without trailing ;
> + if ($line =~ /while\s*\(0\);/) {
Should this also check for uses of 'while (false);' ?
Interestingly enough, we have an instance of 'do/while (false);' in
tests/vhost-user-bridge.c that is NOT in a macro, but is used for the
convenience of being able to 'break;' out early rather than using a
goto. Similarly for chardev/char-serial.c using 'while (0);' outside of
a macro. Those may be worth rewriting to use goto as separate patches
if we want to restrict ALL use of 'while \((0|false)\);'
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2017-11-30 17:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-30 13:41 [Qemu-devel] [PATCH 0/3] macro do/while (0) cleanup Eric Blake
2017-11-30 13:41 ` [Qemu-devel] [PATCH 1/3] net: Drop unusual use of do { } while (0); Eric Blake
2017-11-30 16:08 ` Thomas Huth
2017-11-30 13:41 ` [Qemu-devel] [PATCH 2/3] mips: Tweak location of ';' in macros Eric Blake
2017-11-30 15:33 ` Philippe Mathieu-Daudé
2017-11-30 13:41 ` [Qemu-devel] [PATCH 3/3] maint: Fix macros with broken 'do/while(0); ' usage Eric Blake
2017-11-30 13:54 ` Cornelia Huck
2017-11-30 14:43 ` Michael S. Tsirkin
2017-11-30 14:55 ` Eric Blake
2017-11-30 14:56 ` Dr. David Alan Gilbert
2017-12-04 0:45 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2017-11-30 14:01 ` [Qemu-devel] [PATCH 4/3] checkpatch: Enforce proper do/while (0) style Eric Blake
2017-11-30 17:00 ` Eric Blake [this message]
2017-12-01 7:31 ` Markus Armbruster
2017-12-01 14:22 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=04c922b4-7287-61e7-1afc-4e64f39c52a5@redhat.com \
--to=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).