Skip to content

Commit 5c60300

Browse files
committed
virtio_console: reset on out of memory
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: [email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent aa44ec8 commit 5c60300

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/char/virtio_console.c

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

20912091
spin_lock_init(&portdev->ports_lock);
20922092
INIT_LIST_HEAD(&portdev->ports);
2093+
INIT_LIST_HEAD(&portdev->list);
20932094

20942095
virtio_device_ready(portdev->vdev);
20952096

@@ -2107,8 +2108,15 @@ static int virtcons_probe(struct virtio_device *vdev)
21072108
if (!nr_added_bufs) {
21082109
dev_err(&vdev->dev,
21092110
"Error allocating buffers for control queue\n");
2110-
err = -ENOMEM;
2111-
goto free_vqs;
2111+
/*
2112+
* The host might want to notify mgmt sw about device
2113+
* add failure.
2114+
*/
2115+
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
2116+
VIRTIO_CONSOLE_DEVICE_READY, 0);
2117+
/* Device was functional: we need full cleanup. */
2118+
virtcons_remove(vdev);
2119+
return -ENOMEM;
21122120
}
21132121
} else {
21142122
/*
@@ -2139,11 +2147,6 @@ static int virtcons_probe(struct virtio_device *vdev)
21392147

21402148
return 0;
21412149

2142-
free_vqs:
2143-
/* The host might want to notify mgmt sw about device add failure */
2144-
__send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
2145-
VIRTIO_CONSOLE_DEVICE_READY, 0);
2146-
remove_vqs(portdev);
21472150
free_chrdev:
21482151
unregister_chrdev(portdev->chr_major, "virtio-portsdev");
21492152
free:

0 commit comments

Comments
 (0)