Hi,

On 05/07/2013 11:17 PM, Chris Dickens wrote:
> Hi,
>
> I had run into the same issue and agree with your findings 100%. I took a 
> slightly different approach, and wanted to get feedback as well.
>
> --- io.c.orig2013-02-27 14:33:56.000000000 -0800
> +++ io.c2013-05-07 14:07:58.022998738 -0700
> @@ -1374,16 +1374,10 @@
> goto out;
> }
> -r = add_to_flying_list(itransfer);
> +r = usbi_backend->submit_transfer(itransfer);
> if (r)
> goto out;
> -r = usbi_backend->submit_transfer(itransfer);
> -if (r) {
> -usbi_mutex_lock(&ctx->flying_transfers_lock);
> -list_del(&itransfer->list);
> -arm_timerfd_for_next_timeout(ctx);
> -usbi_mutex_unlock(&ctx->flying_transfers_lock);
> -}
> +r = add_to_flying_list(itransfer);
>   out:
> updated_fds = (itransfer->flags & USBI_TRANSFER_UPDATED_FDS);
>
> This approach waits to add the transfer to the flying transfers list until it 
> was successfully submitted.
>
> Is there any harm in this approach?

Yes, with your fix another thread can theoretically complete the handler,
and try to remove it from the list, before it got added.

> As a side note, I see that add_to_flying_list will only ever fail in regards 
> to the timerfd_settime() call. Even if that call fails, the transfer would 
> still have been submitted *and* be in the flying transfers list, but 
> libusb_submit_transfer() would return an error.

Yes I noticed that too, and my patch fixes that too, by doing
the list_del if either one of usbi_backend->submit_transfer or
add_to_flying_list fails.

Regards,

Hans

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to