qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, "Jason Wang" <jasowang@redhat.com>,
	"Si-Wei Liu" <si-wei.liu@oracle.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH] net/vhost-vdpa.c: Fix clang compilation failure
Date: Mon, 31 Oct 2022 10:06:27 -0400	[thread overview]
Message-ID: <Y1/WY6MnQxKRZCvb@fedora> (raw)
In-Reply-To: <20221031132901.1277150-1-peter.maydell@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 1861 bytes --]

On Mon, Oct 31, 2022 at 01:29:01PM +0000, Peter Maydell wrote:
> Commit 8801ccd0500437 introduced a compilation failure with clang
> version 10.0.0-4ubuntu1:
> 
> ../../net/vhost-vdpa.c:654:16: error: variable 'vdpa_device_fd' is
> used uninitialized whenever 'if' condition is false
> [-Werror,-Wsometimes-uninitialized]
>     } else if (opts->has_vhostfd) {
>                ^~~~~~~~~~~~~~~~~
> ../../net/vhost-vdpa.c:662:33: note: uninitialized use occurs here
>     r = vhost_vdpa_get_features(vdpa_device_fd, &features, errp);
>                                 ^~~~~~~~~~~~~~
> ../../net/vhost-vdpa.c:654:12: note: remove the 'if' if its condition
> is always true
>     } else if (opts->has_vhostfd) {
>            ^~~~~~~~~~~~~~~~~~~~~~~
> ../../net/vhost-vdpa.c:629:23: note: initialize the variable
> 'vdpa_device_fd' to silence this warning
>     int vdpa_device_fd;
>                       ^
>                        = 0
> 1 error generated.
> 
> It's a false positive -- the compiler doesn't manage to figure out
> that the error checks further up mean that there's no code path where
> vdpa_device_fd isn't initialized.  Put another way, the problem is
> that we check "if (opts->has_vhostfd)" when in fact that condition
> must always be true.  A cleverer static analyser would probably warn
> that we were checking an always-true condition.
> 
> Fix the compilation failure by removing the unnecessary if().
> 
> Fixes: 8801ccd0500437 ("vhost-vdpa: allow passing opened vhostfd to vhost-vdpa")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> Stefan, do you want to apply this directly as a build fix?
> ---
>  net/vhost-vdpa.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks, applied to the staging tree:
https://gitlab.com/qemu-project/qemu/commits/staging

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2022-10-31 14:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 13:29 [PATCH] net/vhost-vdpa.c: Fix clang compilation failure Peter Maydell
2022-10-31 14:06 ` Stefan Hajnoczi [this message]

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=Y1/WY6MnQxKRZCvb@fedora \
    --to=stefanha@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=jasowang@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=si-wei.liu@oracle.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).