]> git.hungrycats.org Git - linux/commitdiff
[PATCH] USB: fix a thread-exit problem at module unload
authorMatthew Dharm <mdharm-usb@one-eyed-alien.net>
Fri, 7 Nov 2003 02:07:03 +0000 (18:07 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Fri, 7 Nov 2003 02:07:03 +0000 (18:07 -0800)
This patch fixes a thread-exit problem when the usb-storage module is
unloaded with a preemptable kernel.  Please refer to the comments in the
code for more detail.

drivers/usb/storage/usb.c

index 0a1a22b1cba9a6d8ec3f08216dbcbdb7dd765850..fdec517bc3c53038d1354edb6fe42e9e92d7469f 100644 (file)
@@ -417,10 +417,21 @@ static int usb_stor_control_thread(void * __us)
                scsi_unlock(host);
        } /* for (;;) */
 
-       /* notify the exit routine that we're actually exiting now */
-       complete(&(us->notify));
-
-       return 0;
+       /* notify the exit routine that we're actually exiting now 
+        *
+        * complete()/wait_for_completion() is similar to up()/down(),
+        * except that complete() is safe in the case where the structure
+        * is getting deleted in a parallel mode of execution (i.e. just
+        * after the down() -- that's necessary for the thread-shutdown
+        * case.
+        *
+        * complete_and_exit() goes even further than this -- it is safe in
+        * the case that the thread of the caller is going away (not just
+        * the structure) -- this is necessary for the module-remove case.
+        * This is important in preemption kernels, which transfer the flow
+        * of execution immediately upon a complete().
+        */
+       complete_and_exit(&(us->notify), 0);
 }      
 
 /***********************************************************************