aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost/test.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/test.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/test.c')
-rw-r--r--drivers/vhost/test.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index 91d6f060aade..be65414d5bb1 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -219,13 +219,20 @@ static long vhost_test_reset_owner(struct vhost_test *n)
219{ 219{
220 void *priv = NULL; 220 void *priv = NULL;
221 long err; 221 long err;
222 struct vhost_memory *memory;
223
222 mutex_lock(&n->dev.mutex); 224 mutex_lock(&n->dev.mutex);
223 err = vhost_dev_check_owner(&n->dev); 225 err = vhost_dev_check_owner(&n->dev);
224 if (err) 226 if (err)
225 goto done; 227 goto done;
228 memory = vhost_dev_reset_owner_prepare();
229 if (!memory) {
230 err = -ENOMEM;
231 goto done;
232 }
226 vhost_test_stop(n, &priv); 233 vhost_test_stop(n, &priv);
227 vhost_test_flush(n); 234 vhost_test_flush(n);
228 err = vhost_dev_reset_owner(&n->dev); 235 vhost_dev_reset_owner(&n->dev, memory);
229done: 236done:
230 mutex_unlock(&n->dev.mutex); 237 mutex_unlock(&n->dev.mutex);
231 return err; 238 return err;