USB: usbtest: prevent a divide by zero bug
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 17 Nov 2012 15:06:11 +0000 (18:06 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Nov 2012 21:32:26 +0000 (13:32 -0800)
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>
drivers/usb/misc/usbtest.c

index f10bd970d50a741ed1ad1a4d74bfc39708ebf2e7..7667b12f2ff5b0a0a32cd236d6d6e5d970e6cc47 100644 (file)
@@ -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;