]> git.baikalelectronics.ru Git - kernel.git/commitdiff
um: virtio_uml: fix memory leak on init failures
authorJohannes Berg <johannes.berg@intel.com>
Fri, 25 Jun 2021 08:34:37 +0000 (10:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 26 Sep 2021 12:07:08 +0000 (14:07 +0200)
commit 7ad28e0df7ee9dbcb793bb88dd81d4d22bb9a10e upstream.

If initialization fails, e.g. because the connection failed,
we leak the 'vu_dev'. Fix that. Reported by smatch.

Fixes: c27216ae3068 ("um: drivers: Add virtio vhost-user driver")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/um/drivers/virtio_uml.c

index 18618af3835f9b150fd0e13e295382efd0bd5d24..936e17eab336023c614a92f3fd1e72c91f8a383d 100644 (file)
@@ -994,7 +994,7 @@ static int virtio_uml_probe(struct platform_device *pdev)
                rc = os_connect_socket(pdata->socket_path);
        } while (rc == -EINTR);
        if (rc < 0)
-               return rc;
+               goto error_free;
        vu_dev->sock = rc;
 
        rc = vhost_user_init(vu_dev);
@@ -1010,6 +1010,8 @@ static int virtio_uml_probe(struct platform_device *pdev)
 
 error_init:
        os_close_file(vu_dev->sock);
+error_free:
+       kfree(vu_dev);
        return rc;
 }