On Tue, 27 Jun 2006, Oliver Neukum wrote: > Am Dienstag, 27. Juni 2006 16:09 schrieb Franck Bui-Huu: > > Oliver Neukum wrote: > > > Am Dienstag, 27. Juni 2006 09:52 schrieb Franck Bui-Huu: > > >> + expire = timeout ? msecs_to_jiffies(timeout) : > > >> MAX_SCHEDULE_TIMEOUT; > > >> + if (!wait_for_completion_timeout(&done, expire)) { > > >> + usb_unlink_urb(urb); > > >> } > > >> - > > >> + status = urb->status; > > > > > > Hm, is this racy? > > > What happens if usb_unlink_urb() and the completion handler race? > > > If usb_unlink_urb() fails to unlink the URB because it is too late, > > > is it guaranteed that urb->status is valid? > > > In the old version this could not happen because the completion was > > > always done. > > > > well, I'm not sure to understand. Do you mean "what happen if the timeout > > has > > expired, but just before calling usb_unlink_urb() the urb is completed by > > the > > hcd" ? > > > > If so, I think that usb_unlink_urb() handles this case by checking (with > > lock > > held) that the urb is still queued. > > Precisely. If the URB is not queued it'll notice. But you read urb->status > even in that case.
The race between usb_unlink_urb and the completion routine doesn't matter. The core guarantees that urb->status is set correctly no matter what. However, it's important that the URB be completely finished before the routine returns. Remember that the completion handler _will_ be called eventually, no matter what. And urb->status isn't valid until the URB has completed. So if the initial wait_for_completion_timeout() times out, you need to do a second wait_for_completion(). Alan Stern Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel