]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
staging: most: cdev: add missing check for cdev_add failure
authorColin Ian King <colin.king@canonical.com>
Sat, 2 Feb 2019 22:34:49 +0000 (22:34 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Feb 2019 11:36:14 +0000 (12:36 +0100)
Currently the call to cdev_add is missing a check for failure. Fix this by
checking for failure and exiting via a new error path that ensures the
allocated comp_channel struct is kfree'd.

Detected by CoverityScan, CID#1462359 ("Unchecked return value")

Fixes: 9bc79bbcd0c5 ("Staging: most: add MOST driver's aim-cdev module")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/most/cdev/cdev.c

index ea64aabda94ed5d8f25c032c2416c7a53b079560..f2b347cda8b7f5f13cc5889ec7d94371b291d7ec 100644 (file)
@@ -453,7 +453,9 @@ static int comp_probe(struct most_interface *iface, int channel_id,
        c->devno = MKDEV(comp.major, current_minor);
        cdev_init(&c->cdev, &channel_fops);
        c->cdev.owner = THIS_MODULE;
-       cdev_add(&c->cdev, c->devno, 1);
+       retval = cdev_add(&c->cdev, c->devno, 1);
+       if (retval < 0)
+               goto err_free_c;
        c->iface = iface;
        c->cfg = cfg;
        c->channel_id = channel_id;
@@ -485,6 +487,7 @@ err_free_kfifo_and_del_list:
        list_del(&c->list);
 err_del_cdev_and_free_channel:
        cdev_del(&c->cdev);
+err_free_c:
        kfree(c);
 err_remove_ida:
        ida_simple_remove(&comp.minor_id, current_minor);