diff mbox

[for-2.7,2/4] virtio: decrement vq->inuse in virtqueue_discard()

Message ID 1471015978-1123-3-git-send-email-stefanha@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Hajnoczi Aug. 12, 2016, 3:32 p.m. UTC
virtqueue_descard() moves vq->last_avail_idx back so the element can be
popped again.  It's necessary to decrement vq->inuse to avoid "leaking"
the element count.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/virtio/virtio.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Michael S. Tsirkin Aug. 12, 2016, 9:31 p.m. UTC | #1
On Fri, Aug 12, 2016 at 04:32:56PM +0100, Stefan Hajnoczi wrote:
> virtqueue_descard()

discard

> moves vq->last_avail_idx back so the element can be
> popped again.  It's necessary to decrement vq->inuse to avoid "leaking"
> the element count.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

With the correction above

Reviewed-by: Michael S. Tsirkin <mst@redhat.com>


> ---
>  hw/virtio/virtio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 4df8274..00158b6 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -268,6 +268,7 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
>                         unsigned int len)
>  {
>      vq->last_avail_idx--;
> +    vq->inuse--;
>      virtqueue_unmap_sg(vq, elem, len);
>  }
>  
> -- 
> 2.7.4
Cornelia Huck Aug. 15, 2016, 8:24 a.m. UTC | #2
On Fri, 12 Aug 2016 16:32:56 +0100
Stefan Hajnoczi <stefanha@redhat.com> wrote:

> virtqueue_descard() moves vq->last_avail_idx back so the element can be
> popped again.  It's necessary to decrement vq->inuse to avoid "leaking"
> the element count.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  hw/virtio/virtio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 4df8274..00158b6 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -268,6 +268,7 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
>                         unsigned int len)
>  {
>      vq->last_avail_idx--;
> +    vq->inuse--;
>      virtqueue_unmap_sg(vq, elem, len);
>  }
> 

Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
diff mbox

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 4df8274..00158b6 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -268,6 +268,7 @@  void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
                        unsigned int len)
 {
     vq->last_avail_idx--;
+    vq->inuse--;
     virtqueue_unmap_sg(vq, elem, len);
 }