On Tue, 15 Jun 2004, Alan Stern wrote:

> David:
> 
> This patch fixes the bug you ran across in the scatter-gather library.  
> (It includes my earlier change to suppress incorrect error messages as 
> well).

Sorry, that patch had a mistake.  It didn't take into account the 
possibility that the first URB might complete before the second could be 
submitted, causing io->count to reach 0 prematurely.

This patch (as316b) should do a better job.  It retains the strategy of
adjusting io->count when something strange happens -- but now it does so
whenever _anything_ strange happens, rather than only when a submission
fails.

Alan Stern

P.S.: Is there some reason for that strange assignment to io->count inside 
the "for" statement?  I didn't see any, so I moved the assignment earlier.
Also that test for "if (io->status == -EINPROGRESS)" in usb_sg_wait() 
doesn't look like it could ever succeed, so I removed it.



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

===== drivers/usb/core/message.c 1.92 vs edited =====
--- 1.92/drivers/usb/core/message.c     Fri Jun 11 07:49:33 2004
+++ edited/drivers/usb/core/message.c   Wed Jun 16 09:56:54 2004
@@ -248,7 +248,7 @@
                 * unlink pending urbs so they won't rx/tx bad data.
                 */
                for (i = 0, found = 0; i < io->entries; i++) {
-                       if (!io->urbs [i])
+                       if (!io->urbs [i] || !io->urbs [i]->dev)
                                continue;
                        if (found) {
                                status = usb_unlink_urb (io->urbs [i]);
@@ -337,7 +337,7 @@
        if (io->entries <= 0)
                return io->entries;
 
-       io->count = 0;
+       io->count = io->entries;
        io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags);
        if (!io->urbs)
                goto nomem;
@@ -347,7 +347,7 @@
        if (usb_pipein (pipe))
                urb_flags |= URB_SHORT_NOT_OK;
 
-       for (i = 0; i < io->entries; i++, io->count = i) {
+       for (i = 0; i < io->entries; i++) {
                unsigned                len;
 
                io->urbs [i] = usb_alloc_urb (0, mem_flags);
@@ -477,14 +477,6 @@
 
                        /* fail any uncompleted urbs */
                default:
-                       spin_lock_irq (&io->lock);
-                       io->count -= entries - i;
-                       if (io->status == -EINPROGRESS)
-                               io->status = retval;
-                       if (io->count == 0)
-                               complete (&io->complete);
-                       spin_unlock_irq (&io->lock);
-
                        io->urbs [i]->dev = 0;
                        io->urbs [i]->status = retval;
                        dev_dbg (&io->dev->dev, "%s, submit --> %d\n",
@@ -495,6 +487,9 @@
                if (retval && io->status == -ECONNRESET)
                        io->status = retval;
        }
+       io->count -= entries - i;
+       if (io->count == 0)
+               complete (&io->complete);
        spin_unlock_irq (&io->lock);
 
        /* OK, yes, this could be packaged as non-blocking.



-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to