diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2018-04-20 14:00:13 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2018-04-25 13:41:29 -0400 |
commit | 5c60300d68da32ca77f7f978039dc72bfc78b06b (patch) | |
tree | f45f092ae920b4a1c8b990855cde54d7fa5ee1fc | |
parent | aa44ec867030a72e8aa127977e37dec551d8df19 (diff) |
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: stable@vger.kernel.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r-- | drivers/char/virtio_console.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index e8480fe2e1d8..21085515814f 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -2090,6 +2090,7 @@ static int virtcons_probe(struct virtio_device *vdev) | |||
2090 | 2090 | ||
2091 | spin_lock_init(&portdev->ports_lock); | 2091 | spin_lock_init(&portdev->ports_lock); |
2092 | INIT_LIST_HEAD(&portdev->ports); | 2092 | INIT_LIST_HEAD(&portdev->ports); |
2093 | INIT_LIST_HEAD(&portdev->list); | ||
2093 | 2094 | ||
2094 | virtio_device_ready(portdev->vdev); | 2095 | virtio_device_ready(portdev->vdev); |
2095 | 2096 | ||
@@ -2107,8 +2108,15 @@ static int virtcons_probe(struct virtio_device *vdev) | |||
2107 | if (!nr_added_bufs) { | 2108 | if (!nr_added_bufs) { |
2108 | dev_err(&vdev->dev, | 2109 | dev_err(&vdev->dev, |
2109 | "Error allocating buffers for control queue\n"); | 2110 | "Error allocating buffers for control queue\n"); |
2110 | err = -ENOMEM; | 2111 | /* |
2111 | goto free_vqs; | 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; | ||
2112 | } | 2120 | } |
2113 | } else { | 2121 | } else { |
2114 | /* | 2122 | /* |
@@ -2139,11 +2147,6 @@ static int virtcons_probe(struct virtio_device *vdev) | |||
2139 | 2147 | ||
2140 | return 0; | 2148 | return 0; |
2141 | 2149 | ||
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); | ||
2147 | free_chrdev: | 2150 | free_chrdev: |
2148 | unregister_chrdev(portdev->chr_major, "virtio-portsdev"); | 2151 | unregister_chrdev(portdev->chr_major, "virtio-portsdev"); |
2149 | free: | 2152 | free: |