lkml.org 
[lkml]   [2019]   [Nov]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.4 116/132] virtio_console: reset on out of memory
    Date
    From: Michael S. Tsirkin <mst@redhat.com>

    [ Upstream commit 5c60300d68da32ca77f7f978039dc72bfc78b06b ]

    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>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    drivers/char/virtio_console.c | 17 ++++++++++-------
    1 file changed, 10 insertions(+), 7 deletions(-)

    diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
    index df9eab91c2d25..78aab6e246e13 100644
    --- a/drivers/char/virtio_console.c
    +++ b/drivers/char/virtio_console.c
    @@ -2067,6 +2067,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);

    @@ -2084,8 +2085,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 {
    /*
    @@ -2116,11 +2124,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:
    --
    2.20.1


    \
     
     \ /
      Last update: 2019-11-27 21:39    [W:4.118 / U:0.460 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site