All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-trivial] [PATCH] kvm: Silence warning from valgrind
Date: Wed, 29 Apr 2015 09:34:51 +0300	[thread overview]
Message-ID: <55407B8B.1010803@msgid.tls.msk.ru> (raw)
In-Reply-To: <1430153944-24368-1-git-send-email-thuth@redhat.com>

27.04.2015 19:59, Thomas Huth wrote:
> valgrind complains here about uninitialized bytes with the following message:
> 
> ==17814== Syscall param ioctl(generic) points to uninitialised byte(s)
> ==17814==    at 0x466A780: ioctl (in /usr/lib64/power8/libc-2.17.so)
> ==17814==    by 0x100735B7: kvm_vm_ioctl (kvm-all.c:1920)
> ==17814==    by 0x10074583: kvm_set_ioeventfd_mmio (kvm-all.c:574)
> 
> Let's fix it by using a proper struct initializer in kvm_set_ioeventfd_mmio().
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  kvm-all.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index dd44f8c..077b0ed 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -552,13 +552,13 @@ static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val,
>                                    bool assign, uint32_t size, bool datamatch)
>  {
>      int ret;
> -    struct kvm_ioeventfd iofd;
> -
> -    iofd.datamatch = datamatch ? adjust_ioeventfd_endianness(val, size) : 0;
> -    iofd.addr = addr;
> -    iofd.len = size;
> -    iofd.flags = 0;
> -    iofd.fd = fd;
> +    struct kvm_ioeventfd iofd = {
> +        .datamatch = datamatch ? adjust_ioeventfd_endianness(val, size) : 0,
> +        .addr = addr,
> +        .len = size,
> +        .flags = 0,
> +        .fd = fd,
> +    };

Hm.  So, what's the difference?  The same fields are assigned the same
values, why in first case we have some uninitialized data and in second
case everything is initialized?  Does struct initializer zero-fills all
other places (alignments, missing fields etc) ?  If yes, there's no need
to assign zero to flags, btw ;)

Thanks,

/mjt


WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] kvm: Silence warning from valgrind
Date: Wed, 29 Apr 2015 09:34:51 +0300	[thread overview]
Message-ID: <55407B8B.1010803@msgid.tls.msk.ru> (raw)
In-Reply-To: <1430153944-24368-1-git-send-email-thuth@redhat.com>

27.04.2015 19:59, Thomas Huth wrote:
> valgrind complains here about uninitialized bytes with the following message:
> 
> ==17814== Syscall param ioctl(generic) points to uninitialised byte(s)
> ==17814==    at 0x466A780: ioctl (in /usr/lib64/power8/libc-2.17.so)
> ==17814==    by 0x100735B7: kvm_vm_ioctl (kvm-all.c:1920)
> ==17814==    by 0x10074583: kvm_set_ioeventfd_mmio (kvm-all.c:574)
> 
> Let's fix it by using a proper struct initializer in kvm_set_ioeventfd_mmio().
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  kvm-all.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index dd44f8c..077b0ed 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -552,13 +552,13 @@ static int kvm_set_ioeventfd_mmio(int fd, hwaddr addr, uint32_t val,
>                                    bool assign, uint32_t size, bool datamatch)
>  {
>      int ret;
> -    struct kvm_ioeventfd iofd;
> -
> -    iofd.datamatch = datamatch ? adjust_ioeventfd_endianness(val, size) : 0;
> -    iofd.addr = addr;
> -    iofd.len = size;
> -    iofd.flags = 0;
> -    iofd.fd = fd;
> +    struct kvm_ioeventfd iofd = {
> +        .datamatch = datamatch ? adjust_ioeventfd_endianness(val, size) : 0,
> +        .addr = addr,
> +        .len = size,
> +        .flags = 0,
> +        .fd = fd,
> +    };

Hm.  So, what's the difference?  The same fields are assigned the same
values, why in first case we have some uninitialized data and in second
case everything is initialized?  Does struct initializer zero-fills all
other places (alignments, missing fields etc) ?  If yes, there's no need
to assign zero to flags, btw ;)

Thanks,

/mjt

  reply	other threads:[~2015-04-29  6:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 16:59 [Qemu-trivial] [PATCH] kvm: Silence warning from valgrind Thomas Huth
2015-04-27 16:59 ` [Qemu-devel] " Thomas Huth
2015-04-29  6:34 ` Michael Tokarev [this message]
2015-04-29  6:34   ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2015-04-29  6:43   ` Thomas Huth
2015-04-29  6:43     ` [Qemu-devel] " Thomas Huth
2015-04-29  6:50     ` Michael Tokarev
2015-04-29  6:50       ` [Qemu-devel] " Michael Tokarev

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=55407B8B.1010803@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=thuth@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.