On Sun, Mar 17, 2002, David Brownell <[EMAIL PROTECTED]> wrote: > > > > Also it's not clear whether completion handler can free urb or not. > > > > usb-uhci and usb-ohci don't seem to use > > > > urb after calling completion handler (except interrupt and ring transfers > > > > where you obviosly must not free urb) > > > > but uhci uses bunch of fields in urb after calling completion.
I must have missed the original email. There is one small problem with uhci.c (patch appended) where it checks urb->status after the completion handler. It should only do this if it's an auto resubmitting interrupt URB, but we always checked it. Other than that, it does not touch the URB after calling the completion handler *unless* it's an auto resubmitting interrupt URB and it wasn't unlinked in the completion handler. This is standard behaviour of all of the HCD's, and is documented as such. Not quite a "bunch of fields". > > >There are those who think that you can and those who think > > >that you can't. > > >If uhci touches it and you want your driver to work with uhci, > > >you must not free them or fix uhci. > > > > What do other people think ? > > I think that completion handlers should be able to free URBs, > except for periodic URBs that are being resubmitted, but I > know that Oliver has problems with that position. They can't. We need to check to see if it got unlinked and to do that, we need to check urb->status. All of these exceptions are one of the reasons I dislike the current (2.4) URB interface. > In practical terms, I believe some of the HC drivers (I thought > it was only usb-uhci, actually) continue to access URBs in > some cases after they are returned to drivers. I call that sort > of behavior buggy, but for now drivers in 2.4 need to cope. I think the HCD's should be fixed, there's less of them :) Plus, it's the rule of least surprise. We shouldn't expect drivers to workaround bugs or inconsistencies with HCD's. > > This should be fairly easily to fix. But the question is should we fix that > > or should we just say "no completion handler _must_ not free urb" > > because it's fundamentally wrong. > > Not fundamentally wrong. However in 2.5 there's now refcounting > inside URBs so that one won't know exactly when the free happens. > Maybe that stack will eventually be backported to 2.4, but not yet. This is definately the correct way of doing it. JE --- linux-2.4.19-pre3.orig/drivers/usb/uhci.c Sun Mar 17 21:43:12 2002 +++ linux-2.4.19-pre3/drivers/usb/uhci.c Sun Mar 17 21:42:06 2002 @@ -2350,15 +2351,15 @@ urb->dev = NULL; spin_unlock_irqrestore(&urb->lock, flags); - if (urb->complete) { + if (urb->complete) urb->complete(urb); + if (resubmit_interrupt) /* Recheck the status. The completion handler may have */ /* unlinked the resubmitting interrupt URB */ killed = (urb->status == -ENOENT || urb->status == -ECONNABORTED || urb->status == -ECONNRESET); - } if (resubmit_interrupt && !killed) { urb->dev = dev; _______________________________________________ [EMAIL PROTECTED] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel