Browse Source

USB: usbtest: prevent a divide by zero bug

If param->length is zero, then this could lead to a divide by zero bug
later in the function when we do: size %= max;

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Dan Carpenter 12 years ago
parent
commit
564e69893c
1 changed files with 3 additions and 0 deletions
  1. 3 0
      drivers/usb/misc/usbtest.c

+ 3 - 0
drivers/usb/misc/usbtest.c

@@ -423,6 +423,9 @@ alloc_sglist(int nents, int max, int vary)
 	unsigned		i;
 	unsigned		size = max;
 
+	if (max == 0)
+		return NULL;
+
 	sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL);
 	if (!sg)
 		return NULL;