Skip to content

Commit

Permalink
vhost: fix error path in vhost_net_set_backend
Browse files Browse the repository at this point in the history
An error could cause vhost_net_set_backend to exit without unlocking
vq->mutex. Fix this.

Signed-off-by: Jeff Dike <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
cfd-36 authored and mstsirkin committed Mar 7, 2010
1 parent 39286fa commit 1dace8c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/vhost/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
/* Verify that ring has been setup correctly. */
if (!vhost_vq_access_ok(vq)) {
r = -EFAULT;
goto err;
goto err_vq;
}
sock = get_socket(fd);
if (IS_ERR(sock)) {
r = PTR_ERR(sock);
goto err;
goto err_vq;
}

/* start polling new socket */
Expand All @@ -524,12 +524,14 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
vhost_net_disable_vq(n, vq);
rcu_assign_pointer(vq->private_data, sock);
vhost_net_enable_vq(n, vq);
mutex_unlock(&vq->mutex);
done:
if (oldsock) {
vhost_net_flush_vq(n, index);
fput(oldsock->file);
}

err_vq:
mutex_unlock(&vq->mutex);
err:
mutex_unlock(&n->dev.mutex);
return r;
Expand Down

0 comments on commit 1dace8c

Please sign in to comment.