[PATCH] USB: Add timeout to usb_lock_device_for_reset

This patch (as555) modifies the already-awkward
usb_lock_device_for_reset routine in usbcore by adding a timeout.  The
whole point of the routine is that the caller wants to acquire some
semaphores in the wrong order; protecting against the possibility of
deadlock by timing out seems only prudent.

Signed-off-by: Alan Stern <[EMAIL PROTECTED]>
Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>

---
commit 3ea15966ed59f2bc20928c7b0496b4585f6de206
tree 45c392aa393fe4ad245b6593b5a74f212f010637
parent e52b1d3afe698cb77c080ecbe9e745257ff8c81b
author Alan Stern <[EMAIL PROTECTED]> Thu, 11 Aug 2005 10:15:39 -0400
committer Greg Kroah-Hartman <[EMAIL PROTECTED]> Thu, 08 Sep 2005 16:28:21 -0700

 drivers/usb/core/usb.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -912,7 +912,7 @@ int usb_trylock_device(struct usb_device
  * is neither BINDING nor BOUND.  Rather than sleeping to wait for the
  * lock, the routine polls repeatedly.  This is to prevent deadlock with
  * disconnect; in some drivers (such as usb-storage) the disconnect()
- * callback will block waiting for a device reset to complete.
+ * or suspend() method will block waiting for a device reset to complete.
  *
  * Returns a negative error code for failure, otherwise 1 or 0 to indicate
  * that the device will or will not have to be unlocked.  (0 can be
@@ -922,6 +922,8 @@ int usb_trylock_device(struct usb_device
 int usb_lock_device_for_reset(struct usb_device *udev,
                struct usb_interface *iface)
 {
+       unsigned long jiffies_expire = jiffies + HZ;
+
        if (udev->state == USB_STATE_NOTATTACHED)
                return -ENODEV;
        if (udev->state == USB_STATE_SUSPENDED)
@@ -938,6 +940,12 @@ int usb_lock_device_for_reset(struct usb
        }
 
        while (!usb_trylock_device(udev)) {
+
+               /* If we can't acquire the lock after waiting one second,
+                * we're probably deadlocked */
+               if (time_after(jiffies, jiffies_expire))
+                       return -EBUSY;
+
                msleep(15);
                if (udev->state == USB_STATE_NOTATTACHED)
                        return -ENODEV;



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to