Skip to content

Commit 1dace8c

Browse files
cfd-36mstsirkin
authored andcommitted
vhost: fix error path in vhost_net_set_backend
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]>
1 parent 39286fa commit 1dace8c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/vhost/net.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
508508
/* Verify that ring has been setup correctly. */
509509
if (!vhost_vq_access_ok(vq)) {
510510
r = -EFAULT;
511-
goto err;
511+
goto err_vq;
512512
}
513513
sock = get_socket(fd);
514514
if (IS_ERR(sock)) {
515515
r = PTR_ERR(sock);
516-
goto err;
516+
goto err_vq;
517517
}
518518

519519
/* start polling new socket */
@@ -524,12 +524,14 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
524524
vhost_net_disable_vq(n, vq);
525525
rcu_assign_pointer(vq->private_data, sock);
526526
vhost_net_enable_vq(n, vq);
527-
mutex_unlock(&vq->mutex);
528527
done:
529528
if (oldsock) {
530529
vhost_net_flush_vq(n, index);
531530
fput(oldsock->file);
532531
}
532+
533+
err_vq:
534+
mutex_unlock(&vq->mutex);
533535
err:
534536
mutex_unlock(&n->dev.mutex);
535537
return r;

0 commit comments

Comments
 (0)