]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
wusbcore: reduce keepalive threshold from timeout/2 to timeout/3
authorThomas Pugliese <thomas.pugliese@gmail.com>
Thu, 6 Jun 2013 15:40:49 +0000 (10:40 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Jun 2013 18:19:27 +0000 (11:19 -0700)
This patch reduces the keepalive threshold of WUSB host controllers from
timeout/2 to timeout/3.  The keepalive timer fires every timeout/2 ms, but
due to rounding errors and jitter, the host may decide not to send a
keepalive at timeout/2.  By the time the next timer fires, a full timeout
period may have expired causing the device to be disconnected without ever
having been sent a keepalive.  Changing the keepalive threshold to
timeout/3 ensures that at least one keepalive will be sent before a device
is disconnected.  The patch also updates the code to use msecs_to_jiffies
consistently.

Signed-off-by: Thomas Pugliese <thomas.pugliese@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/wusbcore/devconnect.c
drivers/usb/wusbcore/wusbhc.c

index 1d365316960cdad1a0a020d6d2757a0e5f73f85e..33a12788f9ca063c8aae13ce28d9b978f27a372c 100644 (file)
@@ -455,8 +455,8 @@ static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
                        dev_err(dev, "KEEPALIVE: device %u timed out\n",
                                wusb_dev->addr);
                        __wusbhc_dev_disconnect(wusbhc, wusb_port);
-               } else if (time_after(jiffies, wusb_dev->entry_ts + tt/2)) {
-                       /* Approaching timeout cut out, need to refresh */
+               } else if (time_after(jiffies, wusb_dev->entry_ts + tt/3)) {
+                       /* Approaching timeout cut off, need to refresh */
                        ie->bDeviceAddress[keep_alives++] = wusb_dev->addr;
                }
        }
@@ -1062,7 +1062,7 @@ int wusbhc_devconnect_start(struct wusbhc *wusbhc)
        wusbhc->wuie_host_info = hi;
 
        queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
-                          (wusbhc->trust_timeout*CONFIG_HZ)/1000/2);
+                          msecs_to_jiffies(wusbhc->trust_timeout / 2));
 
        return 0;
 
index 0faca16df7656c38f14ba8af22ce9acda5735030..c35ee439481030725c5c2a55842bcefca688e16d 100644 (file)
@@ -75,12 +75,11 @@ static ssize_t wusb_trust_timeout_store(struct device *dev,
                result = -EINVAL;
                goto out;
        }
-       /* FIXME: maybe we should check for range validity? */
-       wusbhc->trust_timeout = trust_timeout;
+       wusbhc->trust_timeout = min_t(unsigned, trust_timeout, 500);
        cancel_delayed_work(&wusbhc->keep_alive_timer);
        flush_workqueue(wusbd);
        queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
-                          (trust_timeout * CONFIG_HZ)/1000/2);
+                          msecs_to_jiffies(wusbhc->trust_timeout / 2));
 out:
        return result < 0 ? result : size;
 }