usbvision: fix leak of usb_dev on failure paths in usbvision_probe()
authorAlexey Khoroshilov <khoroshilov@ispras.ru>
Fri, 27 Mar 2015 22:39:09 +0000 (19:39 -0300)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 Jun 2016 08:42:50 +0000 (10:42 +0200)
commit afd270d1a45043cef14341bcceff62ed50e8dc9a upstream.

There is no usb_put_dev() on failure paths in usbvision_probe().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/media/usb/usbvision/usbvision-video.c

index 443e7833cc166a7c4b769e807d1e8f264499f123..017f4d17c7f5d4297177c497fd7f915c52688f6f 100644 (file)
@@ -1521,7 +1521,7 @@ static int usbvision_probe(struct usb_interface *intf,
        const struct usb_host_interface *interface;
        struct usb_usbvision *usbvision = NULL;
        const struct usb_endpoint_descriptor *endpoint;
-       int model, i;
+       int model, i, ret;
 
        PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
                                dev->descriptor.idVendor,
@@ -1530,7 +1530,8 @@ static int usbvision_probe(struct usb_interface *intf,
        model = devid->driver_info;
        if (model < 0 || model >= usbvision_device_data_size) {
                PDEBUG(DBG_PROBE, "model out of bounds %d", model);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_usb;
        }
        printk(KERN_INFO "%s: %s found\n", __func__,
                                usbvision_device_data[model].model_string);
@@ -1545,18 +1546,21 @@ static int usbvision_probe(struct usb_interface *intf,
                    __func__, ifnum);
                dev_err(&intf->dev, "%s: Endpoint attributes %d",
                    __func__, endpoint->bmAttributes);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_usb;
        }
        if (usb_endpoint_dir_out(endpoint)) {
                dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
                    __func__, ifnum);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_usb;
        }
 
        usbvision = usbvision_alloc(dev, intf);
        if (usbvision == NULL) {
                dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err_usb;
        }
 
        if (dev->descriptor.bNumConfigurations > 1)
@@ -1575,8 +1579,8 @@ static int usbvision_probe(struct usb_interface *intf,
        usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
        if (usbvision->alt_max_pkt_size == NULL) {
                dev_err(&intf->dev, "usbvision: out of memory!\n");
-               usbvision_release(usbvision);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err_pkt;
        }
 
        for (i = 0; i < usbvision->num_alt; i++) {
@@ -1611,6 +1615,12 @@ static int usbvision_probe(struct usb_interface *intf,
 
        PDEBUG(DBG_PROBE, "success");
        return 0;
+
+err_pkt:
+       usbvision_release(usbvision);
+err_usb:
+       usb_put_dev(dev);
+       return ret;
 }