[PATCH] vhost: compilation fix for GCC-12
Amit Prakash Shukla
amitprakashs at marvell.com
Thu Sep 1 10:49:43 CEST 2022
../lib/vhost/virtio_net.c:941:35: error:
'buf_vec[0].buf_len' may be used uninitialized
[-Werror=maybe-uninitialized]
941 | buf_len = buf_vec[vec_idx].buf_len;
| ~~~~~~~~~~~~~~~~^~~~~~~~
../lib/vhost/virtio_net.c: In function 'virtio_dev_rx_packed':
../lib/vhost/virtio_net.c:1285:27: note: 'buf_vec' declared here
1285 | struct buf_vector buf_vec[BUF_VECTOR_MAX];
| ^~~~~~~
cc1: all warnings being treated as errors
Fixes: 93520085efda ("vhost: add packed ring single enqueue")
Cc: stable at dpdk.org
Signed-off-by: Amit Prakash Shukla <amitprakashs at marvell.com>
---
lib/vhost/virtio_net.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index b3d954aab4..0220bc923c 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -1069,6 +1069,12 @@ vhost_enqueue_single_packed(struct virtio_net *dev,
else
max_tries = 1;
+ /* To avoid GCC-12 warning.
+ * GCC-12 is not evaluating sizeof at compile time.
+ */
+ if (unlikely(size == 0))
+ return -1;
+
while (size > 0) {
/*
* if we tried all available ring items, and still
@@ -1574,6 +1580,12 @@ vhost_enqueue_async_packed(struct virtio_net *dev,
else
max_tries = 1;
+ /* To avoid GCC-12 warning.
+ * GCC-12 is not evaluating sizeof at compile time.
+ */
+ if (unlikely(size == 0))
+ return -1;
+
while (size > 0) {
/*
* if we tried all available ring items, and still
--
2.25.1
More information about the stable
mailing list