[PATCH] virtio_ring: Fix potential mem leak in virtqueue_add_indirect_packed

From: Yue Haibing
Date: Tue Mar 12 2019 - 03:07:16 EST


From: YueHaibing <yuehaibing@xxxxxxxxxx>

'desc' should be freed before leaving from err handing path.

Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
Signed-off-by: YueHaibing <yuehaibing@xxxxxxxxxx>
---
drivers/virtio/virtio_ring.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index a0b07c3..9d95d9c 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -991,6 +991,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,

if (unlikely(vq->vq.num_free < 1)) {
pr_debug("Can't add buf len 1 - avail = 0\n");
+ kfree(desc);
END_USE(vq);
return -ENOSPC;
}
--
2.7.0