From: David Marchand <david.marchand@redhat.com>
To: Min Zhou <zhoumin@loongson.cn>
Cc: "Xia, Chenbo" <chenbo.xia@intel.com>, dev <dev@dpdk.org>,
maobibo@loongson.cn, Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: Re: [PATCH v1] vhost: fix build
Date: Wed, 24 Aug 2022 16:09:54 +0200 [thread overview]
Message-ID: <CAJFAV8w8Lzi3Sa5yg38YDzAPLd=wA5O+QoWMQDBqkK0nUog2Xg@mail.gmail.com> (raw)
In-Reply-To: <20220822074233.209414-1-zhoumin@loongson.cn>
On Mon, Aug 22, 2022 at 9:42 AM Min Zhou <zhoumin@loongson.cn> wrote:
>
> This patch fixes the following build failure seen on CentOS 8
> with gcc 12.1 because of uninitialized struct variable:
>
> [..]
> ../lib/vhost/virtio_net.c:1159:18: warning: 'buf_vec[0].buf_addr' may be used uninitialized [-Wmaybe-uninitialized]
> 1159 | buf_addr = buf_vec[vec_idx].buf_addr;
> | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> [..]
I don't like setting the whole variable to 0 just to silence a
warning, like pushing something under the rug.
This is all the more suspicious as there is other code in this file
that does almost the same.
I had seen a similar warning during 22.07 when cross compiling but did
not investigate much.
The patch that I had written at the time was:
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 35fa4670fd..9446e33aa7 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -1153,7 +1153,7 @@ mbuf_to_desc(struct virtio_net *dev, struct
vhost_virtqueue *vq,
struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL;
struct vhost_async *async = vq->async;
- if (unlikely(m == NULL))
+ if (unlikely(m == NULL || nr_vec == 0))
return -1;
buf_addr = buf_vec[vec_idx].buf_addr;
Could you see if this fixes your issue?
If it is the case, it may be worth better understanding what bothers
the compiler in the current code.
--
David Marchand
next prev parent reply other threads:[~2022-08-24 14:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 7:42 Min Zhou
2022-08-24 0:45 ` zhoumin
2022-08-24 14:09 ` David Marchand [this message]
2022-08-25 12:36 ` zhoumin
2022-08-25 14:08 ` David Marchand
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='CAJFAV8w8Lzi3Sa5yg38YDzAPLd=wA5O+QoWMQDBqkK0nUog2Xg@mail.gmail.com' \
--to=david.marchand@redhat.com \
--cc=chenbo.xia@intel.com \
--cc=dev@dpdk.org \
--cc=maobibo@loongson.cn \
--cc=maxime.coquelin@redhat.com \
--cc=zhoumin@loongson.cn \
/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).