On Fri, 30 Apr 2004, Oliver Neukum wrote:

> Very, very tempting. Elegant and simple. But I have a problem with it.
> It's entirely legal for a driver to call usb_get_urb() twice. And then we
> have a problem. So I don't think that we should use the refcount.

Yes, it is legal for a driver to do that.  I suspect that very few of them
do, because there's not often a reason for it.  In fact, a recursive grep
of the kernel source shows that usb_get_urb() is mentioned only within
include/linux/usb.h, core/hcd.c, core/urb.c, host/ehci-sched.c, and
host/hc_simple.c.  No drivers call it.  Anyway, we can always document at
the start of the routine that it shouldn't be used if the URB's reference
count has been monkeyed with.

On the other hand, there are some very good reasons for using the refcount 
in that test.  Whatever we test, it needs to be something that is changed 
in giveback_urb after the completion handler returns.  The only field for 
which that is currently true is the refcount.  Remember, at the end of 
giveback_urb usbcore no longer owns the URB; the driver does.  Hence there 
isn't much that giveback_urb can afford to change.

Also, whatever we use, it has to take into account the possibility of 
resubmission (and even the theoretical possibility of nested invocations 
of giveback_urb!).  The only thing that will handle this properly is a 
refcount of some sort.  Yes, we could introduce another one that would 
track just the active submissions -- but why go to all that trouble (and 
introduce yet another field into the already-bloated struct urb) when 
we have a ready-made reference count sitting right there?

Finally, remember this:  If a driver plays around with usb_get_urb() or 
doesn't want to wait the extra couple of milliseconds implied by that 
polling loop, it can always use asynchronous unlinking and just signal a 
struct completion from within its completion handler.

Alan Stern




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE. 
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to