]> git.hungrycats.org Git - linux/commitdiff
[PATCH] tiglusb timeouts
authorRandy Dunlap <randy.dunlap@verizon.net>
Tue, 26 Nov 2002 06:27:06 +0000 (22:27 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Tue, 26 Nov 2002 06:27:06 +0000 (22:27 -0800)
It addresses the timeout parameter in the tiglusb driver.

1.  timeout could be 0, causing a divide-by-zero.
The patch prevents this.

2.  The timeout value to usb_bulk_msg() could be rounded
down to cause a divide-by-zero if timeout was < 10, e.g. 9,
in:
result = usb_bulk_msg (s->dev, pipe, buffer, bytes_to_read,
       &bytes_read, HZ / (timeout / 10));
9 / 10 == 0 => divide-by-zero !!

3.  The timeout value above doesn't do very well on converting
timeout to tenths of seconds.  Even for the default timeout
value of 15 (1.5 seconds), it becomes:
HZ / (15 / 10) == HZ / 1 == HZ, or 1 second.
The patch corrects this formula to use:
(HZ * 10) / timeout

drivers/usb/misc/tiglusb.c

index c535d28da9236eec18bc45015ba64554f5bf6dad..b2ed1ed76bfd3db427278ec54e7dd74a55b3bb21 100644 (file)
@@ -185,7 +185,7 @@ tiglusb_read (struct file *filp, char *buf, size_t count, loff_t * f_pos)
 
        pipe = usb_rcvbulkpipe (s->dev, 1);
        result = usb_bulk_msg (s->dev, pipe, buffer, bytes_to_read,
-                              &bytes_read, HZ / (timeout / 10));
+                              &bytes_read, HZ * 10 / timeout);
        if (result == -ETIMEDOUT) {     /* NAK */
                ret = result;
                if (!bytes_read) {
@@ -242,7 +242,7 @@ tiglusb_write (struct file *filp, const char *buf, size_t count, loff_t * f_pos)
 
        pipe = usb_sndbulkpipe (s->dev, 2);
        result = usb_bulk_msg (s->dev, pipe, buffer, bytes_to_write,
-                              &bytes_written, HZ / (timeout / 10));
+                              &bytes_written, HZ * 10 / timeout);
 
        if (result == -ETIMEDOUT) {     /* NAK */
                warn ("tiglusb_write, NAK received.");
@@ -453,6 +453,8 @@ tiglusb_setup (char *str)
        if (ints[0] > 0) {
                timeout = ints[1];
        }
+       if (!timeout)
+               timeout = TIMAXTIME;
 
        return 1;
 }
@@ -494,6 +496,9 @@ tiglusb_init (void)
 
        info (DRIVER_DESC ", " DRIVER_VERSION);
 
+       if (!timeout)
+               timeout = TIMAXTIME;
+
        return 0;
 }
 
@@ -516,6 +521,6 @@ MODULE_DESCRIPTION (DRIVER_DESC);
 MODULE_LICENSE (DRIVER_LICENSE);
 
 MODULE_PARM (timeout, "i");
-MODULE_PARM_DESC (timeout, "Timeout (default=1.5 seconds)");
+MODULE_PARM_DESC (timeout, "Timeout in tenths of seconds (default=1.5 seconds)");
 
 /* --------------------------------------------------------------------- */