aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsias He <asias@redhat.com>2013-05-06 04:38:23 -0400
committerMichael S. Tsirkin <mst@redhat.com>2013-07-07 07:38:26 -0400
commit6d5e6aa860a33fdfcd07de658c8108027c06c329 (patch)
tree0a456165a4e0380b9498529a01848ac8ea0849b2
parentc38e39c378f46f00ce922dd40a91043a9925c28d (diff)
vhost: Simplify dev->vqs[i] access
Signed-off-by: Asias He <asias@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--drivers/vhost/vhost.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 60aa5ad09a2f..4d135b1a861e 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -251,17 +251,16 @@ static void vhost_vq_free_iovecs(struct vhost_virtqueue *vq)
251/* Helper to allocate iovec buffers for all vqs. */ 251/* Helper to allocate iovec buffers for all vqs. */
252static long vhost_dev_alloc_iovecs(struct vhost_dev *dev) 252static long vhost_dev_alloc_iovecs(struct vhost_dev *dev)
253{ 253{
254 struct vhost_virtqueue *vq;
254 int i; 255 int i;
255 256
256 for (i = 0; i < dev->nvqs; ++i) { 257 for (i = 0; i < dev->nvqs; ++i) {
257 dev->vqs[i]->indirect = kmalloc(sizeof *dev->vqs[i]->indirect * 258 vq = dev->vqs[i];
258 UIO_MAXIOV, GFP_KERNEL); 259 vq->indirect = kmalloc(sizeof *vq->indirect * UIO_MAXIOV,
259 dev->vqs[i]->log = kmalloc(sizeof *dev->vqs[i]->log * UIO_MAXIOV, 260 GFP_KERNEL);
260 GFP_KERNEL); 261 vq->log = kmalloc(sizeof *vq->log * UIO_MAXIOV, GFP_KERNEL);
261 dev->vqs[i]->heads = kmalloc(sizeof *dev->vqs[i]->heads * 262 vq->heads = kmalloc(sizeof *vq->heads * UIO_MAXIOV, GFP_KERNEL);
262 UIO_MAXIOV, GFP_KERNEL); 263 if (!vq->indirect || !vq->log || !vq->heads)
263 if (!dev->vqs[i]->indirect || !dev->vqs[i]->log ||
264 !dev->vqs[i]->heads)
265 goto err_nomem; 264 goto err_nomem;
266 } 265 }
267 return 0; 266 return 0;
@@ -283,6 +282,7 @@ static void vhost_dev_free_iovecs(struct vhost_dev *dev)
283long vhost_dev_init(struct vhost_dev *dev, 282long vhost_dev_init(struct vhost_dev *dev,
284 struct vhost_virtqueue **vqs, int nvqs) 283 struct vhost_virtqueue **vqs, int nvqs)
285{ 284{
285 struct vhost_virtqueue *vq;
286 int i; 286 int i;
287 287
288 dev->vqs = vqs; 288 dev->vqs = vqs;
@@ -297,15 +297,16 @@ long vhost_dev_init(struct vhost_dev *dev,
297 dev->worker = NULL; 297 dev->worker = NULL;
298 298
299 for (i = 0; i < dev->nvqs; ++i) { 299 for (i = 0; i < dev->nvqs; ++i) {
300 dev->vqs[i]->log = NULL; 300 vq = dev->vqs[i];
301 dev->vqs[i]->indirect = NULL; 301 vq->log = NULL;
302 dev->vqs[i]->heads = NULL; 302 vq->indirect = NULL;
303 dev->vqs[i]->dev = dev; 303 vq->heads = NULL;
304 mutex_init(&dev->vqs[i]->mutex); 304 vq->dev = dev;
305 vhost_vq_reset(dev, dev->vqs[i]); 305 mutex_init(&vq->mutex);
306 if (dev->vqs[i]->handle_kick) 306 vhost_vq_reset(dev, vq);
307 vhost_poll_init(&dev->vqs[i]->poll, 307 if (vq->handle_kick)
308 dev->vqs[i]->handle_kick, POLLIN, dev); 308 vhost_poll_init(&vq->poll, vq->handle_kick,
309 POLLIN, dev);
309 } 310 }
310 311
311 return 0; 312 return 0;