Skip to content

Commit 6143a3c

Browse files
mstsirkinbwhacks
authored andcommitted
virtio_console: reset on out of memory
commit 5c60300 upstream. 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. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent da1ced7 commit 6143a3c

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

drivers/char/virtio_console.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,7 @@ static int virtcons_probe(struct virtio_device *vdev)
20732073

20742074
spin_lock_init(&portdev->ports_lock);
20752075
INIT_LIST_HEAD(&portdev->ports);
2076+
INIT_LIST_HEAD(&portdev->list);
20762077

20772078
INIT_WORK(&portdev->config_work, &config_work_handler);
20782079
INIT_WORK(&portdev->control_work, &control_work_handler);
@@ -2088,8 +2089,15 @@ static int virtcons_probe(struct virtio_device *vdev)
20882089
if (!nr_added_bufs) {
20892090
dev_err(&vdev->dev,
20902091
"Error allocating buffers for control queue\n");
2091-
err = -ENOMEM;
2092-
goto free_vqs;
2092+
/*
2093+
* The host might want to notify mgmt sw about device
2094+
* add failure.
2095+
*/
2096+
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
2097+
VIRTIO_CONSOLE_DEVICE_READY, 0);
2098+
/* Device was functional: we need full cleanup. */
2099+
virtcons_remove(vdev);
2100+
return -ENOMEM;
20932101
}
20942102
} else {
20952103
/*
@@ -2120,11 +2128,6 @@ static int virtcons_probe(struct virtio_device *vdev)
21202128

21212129
return 0;
21222130

2123-
free_vqs:
2124-
/* The host might want to notify mgmt sw about device add failure */
2125-
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
2126-
VIRTIO_CONSOLE_DEVICE_READY, 0);
2127-
remove_vqs(portdev);
21282131
free_chrdev:
21292132
unregister_chrdev(portdev->chr_major, "virtio-portsdev");
21302133
free:

0 commit comments

Comments
 (0)