Skip to contentSkip to conversation

virtio_ring: fix uninitialized used value

PATCH In review Jason Wang 2 participants 3 messages Jul 25, 2025 – Jul 28, 2025 virtio core

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 virtio_ring: fix uninitialized used value

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.

---
 drivers/virtio/virtio_ring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/virtio/virtio_ring.c +3 -3
index 8f9413acd4e2..7b960ce9a034 100644
@@ -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;
 	}
 
Signature · 1 line
2.39.5
#1 lore raw
Quoted 13 lines · Jason Wang

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.

Quoted 7 lines

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

I squashed but I think you should respin.
also noticed a couple of minor issues.

Quoted 33 lines
---
 drivers/virtio/virtio_ring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/virtio/virtio_ring.c +3 -3
index 8f9413acd4e2..7b960ce9a034 100644
@@ -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;
 	}
 
Signature · 1 line
2.39.5
author
#2 lore raw
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang

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.

Quoted 8 lines
Quoted 4 lines

I squashed but I think you should respin.
also noticed a couple of minor issues.

I think a reppin of this patch should be sufficient.

I can post a new version.

Thanks