Skip to content

Commit

Permalink
virtio_console: reset on out of memory
Browse files Browse the repository at this point in the history
When out of memory and we can't add ctrl vq buffers,
probe fails. Unfortunately the error handling is
out of spec: it calls del_vqs without bothering
to reset the device first.

To fix, call the full cleanup function in this case.

Cc: stable@vger.kernel.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Michael S. Tsirkin committed Apr 25, 2018
1 parent aa44ec8 commit 5c60300
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,7 @@ static int virtcons_probe(struct virtio_device *vdev)

spin_lock_init(&portdev->ports_lock);
INIT_LIST_HEAD(&portdev->ports);
INIT_LIST_HEAD(&portdev->list);

virtio_device_ready(portdev->vdev);

Expand All @@ -2107,8 +2108,15 @@ static int virtcons_probe(struct virtio_device *vdev)
if (!nr_added_bufs) {
dev_err(&vdev->dev,
"Error allocating buffers for control queue\n");
err = -ENOMEM;
goto free_vqs;
/*
* The host might want to notify mgmt sw about device
* add failure.
*/
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
VIRTIO_CONSOLE_DEVICE_READY, 0);
/* Device was functional: we need full cleanup. */
virtcons_remove(vdev);
return -ENOMEM;
}
} else {
/*
Expand Down Expand Up @@ -2139,11 +2147,6 @@ static int virtcons_probe(struct virtio_device *vdev)

return 0;

free_vqs:
/* The host might want to notify mgmt sw about device add failure */
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
VIRTIO_CONSOLE_DEVICE_READY, 0);
remove_vqs(portdev);
free_chrdev:
unregister_chrdev(portdev->chr_major, "virtio-portsdev");
free:
Expand Down

0 comments on commit 5c60300

Please sign in to comment.