[ldv-project] [PATCH] cx231xx: add missing usb_put_dev

Marina Makienko makienko at ispras.ru
Tue Feb 26 10:54:53 MSK 2013


Add missing usb_put_dev on failure path in cx231xx_usb_probe().

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

Signed-off-by: Marina Makienko <makienko at ispras.ru>
---
 drivers/media/usb/cx231xx/cx231xx-cards.c |   56 ++++++++++++++---------------
 1 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 8d52956..b4fff0f 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1064,7 +1064,7 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	 * Interface number 1 - AV interface (handled by this driver)
 	 */
 	if (ifnum != 1)
-		return -ENODEV;
+		goto err;
 
 	/* Check to see next free device and mark as used */
 	do {
@@ -1073,7 +1073,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 			/* No free device slots */
 			cx231xx_err(DRIVER_NAME ": Supports only %i devices.\n",
 					CX231XX_MAXBOARDS);
-			return -ENOMEM;
+			retval = -ENOMEM;
+			goto err;
 		}
 	} while (test_and_set_bit(nr, &cx231xx_devused));
 
@@ -1082,7 +1083,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	if (dev == NULL) {
 		cx231xx_err(DRIVER_NAME ": out of memory!\n");
 		clear_bit(nr, &cx231xx_devused);
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto err;
 	}
 
 	snprintf(dev->name, 29, "cx231xx #%d", nr);
@@ -1148,9 +1150,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 		cx231xx_err(DRIVER_NAME ": Not found "
 			    "matching IAD interface\n");
 		clear_bit(dev->devno, &cx231xx_devused);
-		kfree(dev);
-		dev = NULL;
-		return -ENODEV;
+		retval = -ENODEV;
+		goto err1;
 	}
 
 	cx231xx_info("registering interface %d\n", ifnum);
@@ -1167,20 +1168,16 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	if (retval) {
 		cx231xx_errdev("v4l2_device_register failed\n");
 		clear_bit(dev->devno, &cx231xx_devused);
-		kfree(dev);
-		dev = NULL;
-		return -EIO;
+		retval = -EIO;
+		goto err1;
 	}
 	/* allocate device struct */
 	retval = cx231xx_init_dev(dev, udev, nr);
 	if (retval) {
 		clear_bit(dev->devno, &cx231xx_devused);
-		v4l2_device_unregister(&dev->v4l2_dev);
-		kfree(dev);
-		dev = NULL;
 		usb_set_intfdata(interface, NULL);
 
-		return retval;
+		goto err2;
 	}
 
 	/* compute alternate max packet sizes for video */
@@ -1200,10 +1197,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	if (dev->video_mode.alt_max_pkt_size == NULL) {
 		cx231xx_errdev("out of memory!\n");
 		clear_bit(dev->devno, &cx231xx_devused);
-		v4l2_device_unregister(&dev->v4l2_dev);
-		kfree(dev);
-		dev = NULL;
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto err2;
 	}
 
 	for (i = 0; i < dev->video_mode.num_alt; i++) {
@@ -1234,10 +1229,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	if (dev->vbi_mode.alt_max_pkt_size == NULL) {
 		cx231xx_errdev("out of memory!\n");
 		clear_bit(dev->devno, &cx231xx_devused);
-		v4l2_device_unregister(&dev->v4l2_dev);
-		kfree(dev);
-		dev = NULL;
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto err2;
 	}
 
 	for (i = 0; i < dev->vbi_mode.num_alt; i++) {
@@ -1269,10 +1262,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
 		cx231xx_errdev("out of memory!\n");
 		clear_bit(dev->devno, &cx231xx_devused);
-		v4l2_device_unregister(&dev->v4l2_dev);
-		kfree(dev);
-		dev = NULL;
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto err2;
 	}
 
 	for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
@@ -1305,10 +1296,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 		if (dev->ts1_mode.alt_max_pkt_size == NULL) {
 			cx231xx_errdev("out of memory!\n");
 			clear_bit(dev->devno, &cx231xx_devused);
-			v4l2_device_unregister(&dev->v4l2_dev);
-			kfree(dev);
-			dev = NULL;
-			return -ENOMEM;
+			retval = -ENOMEM;
+			goto err2;
 		}
 
 		for (i = 0; i < dev->ts1_mode.num_alt; i++) {
@@ -1335,6 +1324,15 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 	request_modules(dev);
 
 	return 0;
+err2:
+	v4l2_device_unregister(&dev->v4l2_dev);
+err1:
+	kfree(dev);
+	dev = NULL;
+err:
+	usb_put_dev(udev);
+
+	return retval;
 }
 
 /*
-- 
1.7.7




More information about the ldv-project mailing list