[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/5] libqos: fix virtio num_free descriptor counter
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 2/5] libqos: fix virtio num_free descriptor counter |
Date: |
Thu, 5 May 2016 09:32:14 +0100 |
The num_free variable is only ever decremented and never used for
anything. Although it is currently useless and could be removed, it
will become important once a function is added to pop buffers from a
virtqueue.
This patch adds the missing num_free initialization and adds assertions
to check that there is enough space to add new descriptors.
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
tests/libqos/virtio.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index d3e4c02..939e5d3 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -140,6 +140,7 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue
*vq, uint64_t addr)
vq->used = (uint64_t)((vq->avail + sizeof(uint16_t) * (3 + vq->size)
+ vq->align - 1) & ~(vq->align - 1));
vq->free_head = 0;
+ vq->num_free = vq->size;
for (i = 0; i < vq->size - 1; i++) {
/* vq->desc[i].addr */
@@ -212,6 +213,7 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data,
uint32_t len, bool write,
uint16_t flags = 0;
uint16_t idx = vq->free_head;
+ g_assert_cmpint(vq->num_free, >=, 1);
vq->num_free--;
if (write) {
@@ -243,6 +245,7 @@ uint32_t qvirtqueue_add_indirect(QVirtQueue *vq,
QVRingIndirectDesc *indirect)
g_assert_cmpint(vq->size, >=, indirect->elem);
g_assert_cmpint(indirect->index, ==, indirect->elem);
+ g_assert_cmpint(vq->num_free, >=, 1);
vq->num_free--;
/* vq->desc[vq->free_head].addr */
--
2.5.5