public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [REVISED] drivers/media/video/stv680.c: check kmalloc() return value.
@ 2007-03-09  7:19 Amit Choudhary
  2007-03-09  8:23 ` Oliver Neukum
  0 siblings, 1 reply; 3+ messages in thread
From: Amit Choudhary @ 2007-03-09  7:19 UTC (permalink / raw)
  To: Linux Kernel

Description: Check the return value of kmalloc() in function stv680_start_stream(), in file drivers/media/video/stv680.c.

Signed-off-by: Amit Choudhary <amit2030@gmail.com>

diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index 6d1ef1e..f35c664 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -687,7 +687,11 @@ static int stv680_start_stream (struct u
 		stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		if (stv680->sbuf[i].data == NULL) {
 			PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i);
-			return -1;
+			for (i = i - 1; i >= 0; i--) {
+				kfree(stv680->sbuf[i].data);
+				stv680->sbuf[i].data = NULL;
+			}
+			return -ENOMEM;
 		}
 	}
 
@@ -698,15 +702,25 @@ static int stv680_start_stream (struct u
 		stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		if (stv680->scratch[i].data == NULL) {
 			PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i);
-			return -1;
+			for (i = i - 1; i >= 0; i--) {
+				kfree(stv680->scratch[i].data);
+				stv680->scratch[i].data = NULL;
+			}
+			goto nomem_sbuf;
 		}
 		stv680->scratch[i].state = BUFFER_UNUSED;
 	}
 
 	for (i = 0; i < STV680_NUMSBUF; i++) {
 		urb = usb_alloc_urb (0, GFP_KERNEL);
-		if (!urb)
-			return -ENOMEM;
+		if (!urb) {
+			for (i = i - 1; i >= 0; i--) {
+				usb_kill_urb(stv680->urb[i]);
+				usb_free_urb(stv680->urb[i]);
+				stv680->urb[i] = NULL;
+			}
+			goto nomem_scratch;
+		}
 
 		/* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */
 		usb_fill_bulk_urb (urb, stv680->udev,
@@ -721,6 +735,18 @@ static int stv680_start_stream (struct u
 
 	stv680->framecount = 0;
 	return 0;
+
+ nomem_scratch:
+	for (i=0; i<STV680_NUMSCRATCH; i++) {
+		kfree(stv680->scratch[i].data);
+		stv680->scratch[i].data = NULL;
+	}
+ nomem_sbuf:
+	for (i=0; i<STV680_NUMSBUF; i++) {
+		kfree(stv680->sbuf[i].data);
+		stv680->sbuf[i].data = NULL;
+	}
+	return -ENOMEM;
 }
 
 static int stv680_stop_stream (struct usb_stv *stv680)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [REVISED] drivers/media/video/stv680.c: check kmalloc() return value.
  2007-03-09  7:19 [PATCH] [REVISED] drivers/media/video/stv680.c: check kmalloc() return value Amit Choudhary
@ 2007-03-09  8:23 ` Oliver Neukum
  0 siblings, 0 replies; 3+ messages in thread
From: Oliver Neukum @ 2007-03-09  8:23 UTC (permalink / raw)
  To: Amit Choudhary; +Cc: Linux Kernel

Am Freitag, 9. März 2007 08:19 schrieb Amit Choudhary:
> Description: Check the return value of kmalloc() in function stv680_start_stream(), in file drivers/media/video/stv680.c.

If you are making usb patches, please send them to the usb list
and maintainers. Secondly, against which kernel is this? It won't
apply to the newest kernel. If you are making patches for the stable
series, say so.

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] [REVISED] drivers/media/video/stv680.c: check kmalloc() return value.
@ 2007-03-11 22:02 Amit Choudhary
  0 siblings, 0 replies; 3+ messages in thread
From: Amit Choudhary @ 2007-03-11 22:02 UTC (permalink / raw)
  To: Linux Kernel; +Cc: linux-usb-devel, video4linux-list

Description: Check the return value of kmalloc() in function stv680_start_stream(), in file drivers/media/video/stv680.c.

Signed-off-by: Amit Choudhary <amit2030@gmail.com>

diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index 6d1ef1e..f35c664 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -687,7 +687,11 @@ static int stv680_start_stream (struct u
 		stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		if (stv680->sbuf[i].data == NULL) {
 			PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i);
-			return -1;
+			for (i = i - 1; i >= 0; i--) {
+				kfree(stv680->sbuf[i].data);
+				stv680->sbuf[i].data = NULL;
+			}
+			return -ENOMEM;
 		}
 	}
 
@@ -698,15 +702,25 @@ static int stv680_start_stream (struct u
 		stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		if (stv680->scratch[i].data == NULL) {
 			PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i);
-			return -1;
+			for (i = i - 1; i >= 0; i--) {
+				kfree(stv680->scratch[i].data);
+				stv680->scratch[i].data = NULL;
+			}
+			goto nomem_sbuf;
 		}
 		stv680->scratch[i].state = BUFFER_UNUSED;
 	}
 
 	for (i = 0; i < STV680_NUMSBUF; i++) {
 		urb = usb_alloc_urb (0, GFP_KERNEL);
-		if (!urb)
-			return -ENOMEM;
+		if (!urb) {
+			for (i = i - 1; i >= 0; i--) {
+				usb_kill_urb(stv680->urb[i]);
+				usb_free_urb(stv680->urb[i]);
+				stv680->urb[i] = NULL;
+			}
+			goto nomem_scratch;
+		}
 
 		/* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */
 		usb_fill_bulk_urb (urb, stv680->udev,
@@ -721,6 +735,18 @@ static int stv680_start_stream (struct u
 
 	stv680->framecount = 0;
 	return 0;
+
+ nomem_scratch:
+	for (i=0; i<STV680_NUMSCRATCH; i++) {
+		kfree(stv680->scratch[i].data);
+		stv680->scratch[i].data = NULL;
+	}
+ nomem_sbuf:
+	for (i=0; i<STV680_NUMSBUF; i++) {
+		kfree(stv680->sbuf[i].data);
+		stv680->sbuf[i].data = NULL;
+	}
+	return -ENOMEM;
 }
 
 static int stv680_stop_stream (struct usb_stv *stv680)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-03-11 22:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-09  7:19 [PATCH] [REVISED] drivers/media/video/stv680.c: check kmalloc() return value Amit Choudhary
2007-03-09  8:23 ` Oliver Neukum
  -- strict thread matches above, loose matches on Subject: below --
2007-03-11 22:02 Amit Choudhary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox