Received: from eggs.gnu.org ([2001:4830:134:3::10]:45976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEiE-0006rs-R5 for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayEi3-00014c-6l for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayEi3-00010e-1Z for qemu-devel@nongnu.org; Thu, 05 May 2016 04:32:35 -0400 From: Stefan Hajnoczi Date: Thu, 5 May 2016 09:32:14 +0100 Message-Id: <1462437137-19824-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1462437137-19824-1-git-send-email-stefanha@redhat.com> References: <1462437137-19824-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 2/5] libqos: fix virtio num_free descriptor counter List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Marc=20Mar=C3=AD?= , Stefan Hajnoczi 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 --- 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