qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Raphael Norwitz <raphael.s.norwitz@gmail.com>,
	qemu-devel@nongnu.org, mst@redhat.com, qemu-trivial@nongnu.org
Subject: Re: [PATCH] Fix erroneous double negation in conditional
Date: Thu, 7 May 2020 15:28:24 -0500	[thread overview]
Message-ID: <62e04219-9254-3210-e948-e6049f535da3@redhat.com> (raw)
In-Reply-To: <CAFubqFt+KVJFYCEimgdTYRiiBm9y9ZRvSshxRv0kizRcUZTkLQ@mail.gmail.com>

On 5/7/20 3:06 PM, Raphael Norwitz wrote:
> In vhost_migration_log() there is the following check:
>      if(!!enable == dev->log_enabled) {
>          return 0;
>      }
> 
> The double negative “!!” is unnecessary and bad coding style. This
> change removes it.

!!int or !!ptr is not bad coding style - it is the shortest way to 
compare a non-bool against 0, and canonicalize the result back into bool 
(that is, convert all non-zero values into '1').  But !!bool is a waste 
of typing, since bool is already in the proper form.  Your patch as-is 
is incorrect; since the function declares 'int enable', this is using 
the !!int form which is not bad coding style.

On the other hand, looking at this function closer, we see that 
vhost_migration_log() is static, so all uses lie within this file.  And 
the callers are:

static void vhost_log_global_start(MemoryListener *listener)
     r = vhost_migration_log(listener, true);
static void vhost_log_global_stop(MemoryListener *listener)
     r = vhost_migration_log(listener, false);

and looking at struct vhost_dev, its log_enabled member is bool.

So the _real_ problem with this file is that it uses 'int enable' rather 
than 'bool enable'.  And once you fix the parameter type, then you are 
indeed correct that you would have a !!bool scenario worth cleaning up.

Looking forward to v2 along those lines.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2020-05-07 20:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 20:06 [PATCH] Fix erroneous double negation in conditional Raphael Norwitz
2020-05-07 20:28 ` Eric Blake [this message]
     [not found] <1588046669-24706-1-git-send-email-raphael.norwitz@nutanix.com>
2020-05-07 20:34 ` Michael S. Tsirkin

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=62e04219-9254-3210-e948-e6049f535da3@redhat.com \
    --to=eblake@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=raphael.s.norwitz@gmail.com \
    /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).