From: Peter Stuge Date: Mon, 13 Feb 2012 15:59:51 +0000 (+0100) Subject: Do not call timerfd functions when timerfd is not being used X-Git-Tag: upstream/1.0.21~727 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4630fc22cff8ad3e1afa9b223378c0aabe282b5c;p=platform%2Fupstream%2Flibusb.git Do not call timerfd functions when timerfd is not being used When libusb was built with timerfd support but used on a system without timerfd support the library would hang indefinitely on completion of the first transfer, since timerfd functions were being called unconditionally and the error returned when timerfd was not being used caused a confused internal state. Many thanks to Ivo Smits for looking into the issue, proposing an initial solution, and helping with testing! Fixes #73. --- diff --git a/libusb/io.c b/libusb/io.c index c4b3635..bb6e275 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1439,7 +1439,7 @@ int usbi_handle_transfer_completion(struct usbi_transfer *itransfer, USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); struct libusb_context *ctx = TRANSFER_CTX(transfer); uint8_t flags; - int r; + int r = 0; /* FIXME: could be more intelligent with the timerfd here. we don't need * to disarm the timerfd if there was no timer running, and we only need @@ -1448,12 +1448,13 @@ int usbi_handle_transfer_completion(struct usbi_transfer *itransfer, usbi_mutex_lock(&ctx->flying_transfers_lock); list_del(&itransfer->list); - r = arm_timerfd_for_next_timeout(ctx); + if (usbi_using_timerfd(ctx)) + r = arm_timerfd_for_next_timeout(ctx); usbi_mutex_unlock(&ctx->flying_transfers_lock); - if (r < 0) { - return r; - } else if (r == 0) { + if (usbi_using_timerfd(ctx)) { + if (r < 0) + return r; r = disarm_timerfd(ctx); if (r < 0) return r;