Commit 6d5e6aa8 authored by Asias He's avatar Asias He Committed by Michael S. Tsirkin

vhost: Simplify dev->vqs[i] access

Signed-off-by: default avatarAsias He <asias@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent c38e39c3
...@@ -251,17 +251,16 @@ static void vhost_vq_free_iovecs(struct vhost_virtqueue *vq) ...@@ -251,17 +251,16 @@ static void vhost_vq_free_iovecs(struct vhost_virtqueue *vq)
/* Helper to allocate iovec buffers for all vqs. */ /* Helper to allocate iovec buffers for all vqs. */
static long vhost_dev_alloc_iovecs(struct vhost_dev *dev) static long vhost_dev_alloc_iovecs(struct vhost_dev *dev)
{ {
struct vhost_virtqueue *vq;
int i; int i;
for (i = 0; i < dev->nvqs; ++i) { for (i = 0; i < dev->nvqs; ++i) {
dev->vqs[i]->indirect = kmalloc(sizeof *dev->vqs[i]->indirect * vq = dev->vqs[i];
UIO_MAXIOV, GFP_KERNEL); vq->indirect = kmalloc(sizeof *vq->indirect * UIO_MAXIOV,
dev->vqs[i]->log = kmalloc(sizeof *dev->vqs[i]->log * UIO_MAXIOV, GFP_KERNEL);
GFP_KERNEL); vq->log = kmalloc(sizeof *vq->log * UIO_MAXIOV, GFP_KERNEL);
dev->vqs[i]->heads = kmalloc(sizeof *dev->vqs[i]->heads * vq->heads = kmalloc(sizeof *vq->heads * UIO_MAXIOV, GFP_KERNEL);
UIO_MAXIOV, GFP_KERNEL); if (!vq->indirect || !vq->log || !vq->heads)
if (!dev->vqs[i]->indirect || !dev->vqs[i]->log ||
!dev->vqs[i]->heads)
goto err_nomem; goto err_nomem;
} }
return 0; return 0;
...@@ -283,6 +282,7 @@ static void vhost_dev_free_iovecs(struct vhost_dev *dev) ...@@ -283,6 +282,7 @@ static void vhost_dev_free_iovecs(struct vhost_dev *dev)
long vhost_dev_init(struct vhost_dev *dev, long vhost_dev_init(struct vhost_dev *dev,
struct vhost_virtqueue **vqs, int nvqs) struct vhost_virtqueue **vqs, int nvqs)
{ {
struct vhost_virtqueue *vq;
int i; int i;
dev->vqs = vqs; dev->vqs = vqs;
...@@ -297,15 +297,16 @@ long vhost_dev_init(struct vhost_dev *dev, ...@@ -297,15 +297,16 @@ long vhost_dev_init(struct vhost_dev *dev,
dev->worker = NULL; dev->worker = NULL;
for (i = 0; i < dev->nvqs; ++i) { for (i = 0; i < dev->nvqs; ++i) {
dev->vqs[i]->log = NULL; vq = dev->vqs[i];
dev->vqs[i]->indirect = NULL; vq->log = NULL;
dev->vqs[i]->heads = NULL; vq->indirect = NULL;
dev->vqs[i]->dev = dev; vq->heads = NULL;
mutex_init(&dev->vqs[i]->mutex); vq->dev = dev;
vhost_vq_reset(dev, dev->vqs[i]); mutex_init(&vq->mutex);
if (dev->vqs[i]->handle_kick) vhost_vq_reset(dev, vq);
vhost_poll_init(&dev->vqs[i]->poll, if (vq->handle_kick)
dev->vqs[i]->handle_kick, POLLIN, dev); vhost_poll_init(&vq->poll, vq->handle_kick,
POLLIN, dev);
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment