[v2] vhost: compilation fix for GCC-12

Message ID 20220902124152.3231904-1-amitprakashs@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] vhost: compilation fix for GCC-12 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed

Commit Message

Amit Prakash Shukla Sept. 2, 2022, 12:41 p.m. UTC
  ../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@dpdk.org

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
v2:
- Changes for code review suggestion

 lib/vhost/virtio_net.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Bagas Sanjaya Sept. 2, 2022, 12:56 p.m. UTC | #1
On Fri, Sep 02, 2022 at 06:11:52PM +0530, Amit Prakash Shukla wrote:
> ../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@dpdk.org

Please describe what this patch is doing (the current state of code,
why it errored, and how it is fixing the error). Write the description
in imperative mood. I don't see the description other than error message
above.

Also, for stable patches submission, Cc stable@vger.kernel.org.

Thanks.
  
Amit Prakash Shukla Sept. 2, 2022, 3:11 p.m. UTC | #2
Thanks for the feedback.

> -----Original Message-----
> From: Bagas Sanjaya <bagasdotme@gmail.com>
> Sent: Friday, September 2, 2022 6:26 PM
> To: Amit Prakash Shukla <amitprakashs@marvell.com>
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; Chenbo Xia
> <chenbo.xia@intel.com>; dev@dpdk.org; Jerin Jacob Kollanukkaran
> <jerinj@marvell.com>; stable@dpdk.org; Ruifeng.Wang@arm.com
> Subject: [EXT] Re: [PATCH v2] vhost: compilation fix for GCC-12
> 
> External Email
> 
> ----------------------------------------------------------------------
> On Fri, Sep 02, 2022 at 06:11:52PM +0530, Amit Prakash Shukla wrote:
> > ../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@dpdk.org
> 
> Please describe what this patch is doing (the current state of code, why it
> errored, and how it is fixing the error). Write the description in imperative
> mood. I don't see the description other than error message above.
I have pushed v3 incorporating your suggestion regarding description.

> 
> Also, for stable patches submission, Cc stable@vger.kernel.org.
> 
> Thanks.
> 
> --
> An old man doll... just what I always wanted! - Clara
  

Patch

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index b3d954aab4..9b77d3d10f 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -1069,7 +1069,7 @@  vhost_enqueue_single_packed(struct virtio_net *dev,
 	else
 		max_tries = 1;
 
-	while (size > 0) {
+	do {
 		/*
 		 * if we tried all available ring items, and still
 		 * can't get enough buf, it means something abnormal
@@ -1097,7 +1097,7 @@  vhost_enqueue_single_packed(struct virtio_net *dev,
 		avail_idx += desc_count;
 		if (avail_idx >= vq->size)
 			avail_idx -= vq->size;
-	}
+	} while (size > 0);
 
 	if (mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, num_buffers, false) < 0)
 		return -1;
@@ -1574,7 +1574,7 @@  vhost_enqueue_async_packed(struct virtio_net *dev,
 	else
 		max_tries = 1;
 
-	while (size > 0) {
+	do {
 		/*
 		 * if we tried all available ring items, and still
 		 * can't get enough buf, it means something abnormal
@@ -1601,7 +1601,7 @@  vhost_enqueue_async_packed(struct virtio_net *dev,
 		avail_idx += desc_count;
 		if (avail_idx >= vq->size)
 			avail_idx -= vq->size;
-	}
+	} while (size > 0);
 
 	if (unlikely(mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, *nr_buffers, true) < 0))
 		return -1;