public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: mst@redhat.com, jasowang@redhat.com
Cc: xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
	virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
	Naresh Kamboju <naresh.kamboju@linaro.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	"kernelci . org bot" <bot@kernelci.org>,
	Linux Kernel Functional Testing <lkft@linaro.org>
Subject: [PATCH] virtio_ring: fix uninitialized used value
Date: Fri, 25 Jul 2025 16:36:35 +0800	[thread overview]
Message-ID: <20250725083635.73355-1-jasowang@redhat.com> (raw)

Buildbot reports uninitialized used:

drivers/virtio/virtio_ring.c:2113:40: error: variable 'id' is
uninitialized when used here [-Werror,-Wuninitialized]
 2113 |                 BAD_RING(vq, "id %u out of range\n", id);
      |                                                      ^~
drivers/virtio/virtio_ring.c:2077:19: note: initialize the variable
'id' to silence this warning
 2077 |         u16 last_used, id, last_used_idx;
      |                          ^
      |                           = 0
1 error generated.

Fixing this by use last_used instead and drop the complete unused
variable id.

Cc: Naresh Kamboju <naresh.kamboju@linaro.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Reported-by: kernelci.org bot <bot@kernelci.org>
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
---
 drivers/virtio/virtio_ring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 8f9413acd4e2..7b960ce9a034 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -2074,7 +2074,7 @@ static void *virtqueue_get_buf_ctx_packed_in_order(struct vring_virtqueue *vq,
 						   void **ctx)
 {
 	unsigned int num = vq->packed.vring.num;
-	u16 last_used, id, last_used_idx;
+	u16 last_used, last_used_idx;
 	bool used_wrap_counter;
 	void *ret;
 
@@ -2110,11 +2110,11 @@ static void *virtqueue_get_buf_ctx_packed_in_order(struct vring_virtqueue *vq,
 		*len = vq->packed.desc_state[last_used].total_len;
 
 	if (unlikely(last_used >= num)) {
-		BAD_RING(vq, "id %u out of range\n", id);
+		BAD_RING(vq, "id %u out of range\n", last_used);
 		return NULL;
 	}
 	if (unlikely(!vq->packed.desc_state[last_used].data)) {
-		BAD_RING(vq, "id %u is not a head!\n", id);
+		BAD_RING(vq, "id %u is not a head!\n", last_used);
 		return NULL;
 	}
 
-- 
2.39.5


             reply	other threads:[~2025-07-25  8:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-25  8:36 Jason Wang [this message]
2025-07-25 13:11 ` [PATCH] virtio_ring: fix uninitialized used value Michael S. Tsirkin
2025-07-28  3:29   ` Jason Wang

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=20250725083635.73355-1-jasowang@redhat.com \
    --to=jasowang@redhat.com \
    --cc=bot@kernelci.org \
    --cc=eperezma@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkft@linaro.org \
    --cc=mst@redhat.com \
    --cc=naresh.kamboju@linaro.org \
    --cc=rdunlap@infradead.org \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.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