vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
[linux-2.6-block.git] / drivers / vhost / vsock.c
index d6ca1c7ad513ff102fe7b6df8f9caafbd40efdc8..37f0b4274113c6dd8aca659a1e102fa294b48560 100644 (file)
@@ -629,16 +629,18 @@ err:
        return ret;
 }
 
-static int vhost_vsock_stop(struct vhost_vsock *vsock)
+static int vhost_vsock_stop(struct vhost_vsock *vsock, bool check_owner)
 {
        size_t i;
-       int ret;
+       int ret = 0;
 
        mutex_lock(&vsock->dev.mutex);
 
-       ret = vhost_dev_check_owner(&vsock->dev);
-       if (ret)
-               goto err;
+       if (check_owner) {
+               ret = vhost_dev_check_owner(&vsock->dev);
+               if (ret)
+                       goto err;
+       }
 
        for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) {
                struct vhost_virtqueue *vq = &vsock->vqs[i];
@@ -753,7 +755,12 @@ static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
         * inefficient.  Room for improvement here. */
        vsock_for_each_connected_socket(vhost_vsock_reset_orphans);
 
-       vhost_vsock_stop(vsock);
+       /* Don't check the owner, because we are in the release path, so we
+        * need to stop the vsock device in any case.
+        * vhost_vsock_stop() can not fail in this case, so we don't need to
+        * check the return code.
+        */
+       vhost_vsock_stop(vsock, false);
        vhost_vsock_flush(vsock);
        vhost_dev_stop(&vsock->dev);
 
@@ -868,7 +875,7 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
                if (start)
                        return vhost_vsock_start(vsock);
                else
-                       return vhost_vsock_stop(vsock);
+                       return vhost_vsock_stop(vsock, true);
        case VHOST_GET_FEATURES:
                features = VHOST_VSOCK_FEATURES;
                if (copy_to_user(argp, &features, sizeof(features)))