Am Dienstag, 17. September 2002 19:44 schrieb David Brownell:
> > If I unlink my urbs upon disconnect synchronously and resubmit my urbs
> > in the completon handler, is there a race condition between the two?
>
> Don't EVER submit another urb after you've gotten a disconnect()
> callback -- that'd be a bug in your driver. Your disconnect logic
> needs to arrange (first thing!) that no more urbs get submitted.
There's quite subtle a problem here.
In principle disconnect() is not SMP-safe at present by design.
Or to be be extremely pedantic either disconnect() or unlink() is not
SMP-safe by design.
We discussed this several months back.
To summarise:
After disconnect() a device must be absolutely dead,
head cut off and stuffed with garlic. In particular
you must not be executing any driver code after returning from
disconnect() because you may now face module unload.
Of course there must be no active urbs after
disconnect(), even if a completion handler was running at
that time. That condition is very hard to meet.
If you resubmit an URB from the completion handler, you must
check for disconnect running. On UP the following sequence
(pseudocode) is correct (in fact on UP without preempt, forget
about the spinlocks):
completion handler:
spin_lock(&desc->spinlock);
...
if (!desc->on_deathrow)
usb_submit_urb(desc->urb, GFP_ATOMIC);
spin_unlock(&desc->spinlock);
// On SMP here's the window
return;
disconnect:
spin_lock_irq(&desc->spinlock);
desc->on_deathrow = 1;
spin_unlock_irq(&desc->spinlock);
usb_unlink_urb(desc->urb);
return;
We have two options here. Either we hope for synchronize_kernel()
becoming available, or we change usb_unlink_urb() to wait for a running
completion handler, which with the URB reference counting is possible.
Regards
Oliver
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel