Xuan Zhuo
2023-Oct-19 07:09 UTC
[PATCH vhost] virtio_ring: add BUG_ON() when vq is set to premapped mode and vq is not empty
Add BUG_ON check to make sure virtqueue_set_dma_premapped() is not misused. This function must be called immediately after creating the vq, or after vq reset, and before adding any buffers to it. Signed-off-by: Xuan Zhuo <xuanzhuo at linux.alibaba.com> --- drivers/virtio/virtio_ring.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 51d8f3299c10..3a3232272067 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2793,10 +2793,7 @@ int virtqueue_set_dma_premapped(struct virtqueue *_vq) num = vq->packed_ring ? vq->packed.vring.num : vq->split.vring.num; - if (num != vq->vq.num_free) { - END_USE(vq); - return -EINVAL; - } + BUG_ON(num != vq->vq.num_free); if (!vq->use_dma_api) { END_USE(vq); -- 2.32.0.3.g01195cf9f