浏览代码

V4L/DVB (4761): Stv680.c: check kmalloc() return value.

Signed-off-by: Amit Choudhary <amit2030@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Amit Choudhary 18 年之前
父节点
当前提交
c85f49d49f
共有 1 个文件被更改,包括 18 次插入3 次删除
  1. 18 3
      drivers/media/video/stv680.c

+ 18 - 3
drivers/media/video/stv680.c

@@ -687,7 +687,7 @@ static int stv680_start_stream (struct usb_stv *stv680)
 		stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		if (stv680->sbuf[i].data == NULL) {
 		if (stv680->sbuf[i].data == NULL) {
 			PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i);
 			PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i);
-			return -1;
+			goto nomem_err;
 		}
 		}
 	}
 	}
 
 
@@ -698,7 +698,7 @@ static int stv680_start_stream (struct usb_stv *stv680)
 		stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
 		if (stv680->scratch[i].data == NULL) {
 		if (stv680->scratch[i].data == NULL) {
 			PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i);
 			PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i);
-			return -1;
+			goto nomem_err;
 		}
 		}
 		stv680->scratch[i].state = BUFFER_UNUSED;
 		stv680->scratch[i].state = BUFFER_UNUSED;
 	}
 	}
@@ -706,7 +706,7 @@ static int stv680_start_stream (struct usb_stv *stv680)
 	for (i = 0; i < STV680_NUMSBUF; i++) {
 	for (i = 0; i < STV680_NUMSBUF; i++) {
 		urb = usb_alloc_urb (0, GFP_KERNEL);
 		urb = usb_alloc_urb (0, GFP_KERNEL);
 		if (!urb)
 		if (!urb)
-			return -ENOMEM;
+			goto nomem_err;
 
 
 		/* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */
 		/* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */
 		usb_fill_bulk_urb (urb, stv680->udev,
 		usb_fill_bulk_urb (urb, stv680->udev,
@@ -721,6 +721,21 @@ static int stv680_start_stream (struct usb_stv *stv680)
 
 
 	stv680->framecount = 0;
 	stv680->framecount = 0;
 	return 0;
 	return 0;
+
+ nomem_err:
+	for (i = 0; i < STV680_NUMSCRATCH; i++) {
+		kfree(stv680->scratch[i].data);
+		stv680->scratch[i].data = NULL;
+	}
+	for (i = 0; i < STV680_NUMSBUF; i++) {
+		usb_kill_urb(stv680->urb[i]);
+		usb_free_urb(stv680->urb[i]);
+		stv680->urb[i] = NULL;
+		kfree(stv680->sbuf[i].data);
+		stv680->sbuf[i].data = NULL;
+	}
+	return -ENOMEM;
+
 }
 }
 
 
 static int stv680_stop_stream (struct usb_stv *stv680)
 static int stv680_stop_stream (struct usb_stv *stv680)