On Wednesday 16 May 2007 20:20, Pete Zaitcev wrote:
> On Wed, 16 May 2007 18:11:35 +0200, Hans Petter Selasky <[EMAIL PROTECTED]> 
wrote:
> > My "usbd_transfer_start()" returns "void". Your "usb_submit_urb()"
> > returns "int".
>
> We (ok, I) don't like this scheme. In Linux only SCSI uses it,
> primarily because that's how Eric Youngdale defined it in 1992.
> See, there may be other reasons why a transfer would fail, outside
> of memory allocation failure. In such case, an error has to be
> reported. In your design, error is reported through a callback,
> and if the error is detected during the submission, it is reported
> on the context which is submitting. Thus, you cannot hold any
> locks across the submission which the callback is likely to take.
> It's a real pain on SMP and with a multithreaded system.

The lock that you are holding during submission is the same lock that is 
protecting the callback. Actually you can end up calling the 
__usbd_callback() prematurely in my new USB stack, but that is handled just 
fine, through some recurse bits:

void
__usbd_callback(struct usbd_xfer *xfer)
{
        mtx_assert(xfer->priv_mtx, MA_OWNED);

        /* check first recurse flag */
        if(!(xfer->flags & USBD_DEV_RECURSED_1))
        {
                do {
                        /* set both recurse flags */
                        xfer->flags |= (USBD_DEV_RECURSED_2|
                                        USBD_DEV_RECURSED_1);

                        /* call processing routine */
                        (xfer->callback)(xfer);

                /* check second recurse flag */
                } while(!(xfer->flags & USBD_DEV_RECURSED_2));

                /* clear first recurse flag */
                xfer->flags &= ~USBD_DEV_RECURSED_1;
        }
        else
        {
                /* clear second recurse flag */
                xfer->flags &= ~USBD_DEV_RECURSED_2;
        }
        return;
}

Those recurse bits solve the problem if you call "urb_submit()" from the 
callback and you want to return an error.

Two flies have been smacked into one. There is only one error check, and that 
is when the transfer fails. Therefore there is no need to return an error 
by "usbd_transfer_start()".

--HPS

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to