Skip to content

Commit 0c404e4

Browse files
terencelimstsirkin
authored andcommitted
virtio-mem: detach the element from the virtqueue when error occurs
If error occurs while processing the virtio request we should call 'virtqueue_detach_element' to detach the element from the virtqueue before free the elem. Signed-off-by: Li Qiang <[email protected]> Message-Id: <[email protected]> Fixes: 910b257 ("virtio-mem: Paravirtualized memory hot(un)plug") Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a5bd058 commit 0c404e4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

hw/virtio/virtio-mem.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static void virtio_mem_handle_request(VirtIODevice *vdev, VirtQueue *vq)
318318
if (iov_to_buf(elem->out_sg, elem->out_num, 0, &req, len) < len) {
319319
virtio_error(vdev, "virtio-mem protocol violation: invalid request"
320320
" size: %d", len);
321+
virtqueue_detach_element(vq, elem, 0);
321322
g_free(elem);
322323
return;
323324
}
@@ -327,6 +328,7 @@ static void virtio_mem_handle_request(VirtIODevice *vdev, VirtQueue *vq)
327328
virtio_error(vdev, "virtio-mem protocol violation: not enough space"
328329
" for response: %zu",
329330
iov_size(elem->in_sg, elem->in_num));
331+
virtqueue_detach_element(vq, elem, 0);
330332
g_free(elem);
331333
return;
332334
}
@@ -348,6 +350,7 @@ static void virtio_mem_handle_request(VirtIODevice *vdev, VirtQueue *vq)
348350
default:
349351
virtio_error(vdev, "virtio-mem protocol violation: unknown request"
350352
" type: %d", type);
353+
virtqueue_detach_element(vq, elem, 0);
351354
g_free(elem);
352355
return;
353356
}

0 commit comments

Comments
 (0)