aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost/vhost.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2013-04-28 10:12:08 -0400
committerMichael S. Tsirkin <mst@redhat.com>2013-05-01 03:02:54 -0400
commit150b9e51ae975ca1fe468c565870fbc4a96e0574 (patch)
treec708d0c69807c7ac4eb14e86498536c5ec1c6c82 /drivers/vhost/vhost.c
parent061b16cfe3dc7a106dd29b76f6355d84464d126c (diff)
vhost: fix error handling in RESET_OWNER ioctl
RESET_OWNER ioctl would leave the fd in a bad state if memory allocation failed: device is stopped but owner is not reset. Make state changes after allocating memory, such that a failed ioctl has no effect. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/vhost/vhost.c')
-rw-r--r--drivers/vhost/vhost.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 6dcd81c87432..749b5ab5bfbb 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -386,21 +386,19 @@ err_mm:
386 return err; 386 return err;
387} 387}
388 388
389/* Caller should have device mutex */ 389struct vhost_memory *vhost_dev_reset_owner_prepare(void)
390long vhost_dev_reset_owner(struct vhost_dev *dev)
391{ 390{
392 struct vhost_memory *memory; 391 return kmalloc(offsetof(struct vhost_memory, regions), GFP_KERNEL);
393 392}
394 /* Restore memory to default empty mapping. */
395 memory = kmalloc(offsetof(struct vhost_memory, regions), GFP_KERNEL);
396 if (!memory)
397 return -ENOMEM;
398 393
394/* Caller should have device mutex */
395void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_memory *memory)
396{
399 vhost_dev_cleanup(dev, true); 397 vhost_dev_cleanup(dev, true);
400 398
399 /* Restore memory to default empty mapping. */
401 memory->nregions = 0; 400 memory->nregions = 0;
402 RCU_INIT_POINTER(dev->memory, memory); 401 RCU_INIT_POINTER(dev->memory, memory);
403 return 0;
404} 402}
405 403
406void vhost_dev_stop(struct vhost_dev *dev) 404void vhost_dev_stop(struct vhost_dev *dev)