From b1a30e3e3b4f2ef00b7005d87fcfc923886e4b51 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 3 Oct 2011 08:59:21 +0000 Subject: [PATCH] drivers/pn53x_usb: fix timeout computing --- libnfc/drivers/pn53x_usb.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 1372888..ce3b831 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -123,8 +123,13 @@ int pn53x_usb_bulk_read (struct pn53x_usb_data *data, byte_t abtRx[], const size_t szRx, struct timeval *timeout) { int timeout_ms = USB_INFINITE_TIMEOUT; - if (timeout) - timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000; + if (timeout) { + timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000; + if (timeout_ms == USB_INFINITE_TIMEOUT) { + // timeout < 1 ms + timeout_ms++; + } + } int res = usb_bulk_read (data->pudh, data->uiEndPointIn, (char *) abtRx, szRx, timeout_ms); if (res > 0) { @@ -523,6 +528,10 @@ read: // No user-provided timeout, we will wait infinitely but we need nfc_abort_command() mecanism. usb_timeout = fixed_timeout; } + if ((usb_timeout.tv_sec == 0) && (usb_timeout.tv_usec == 0)) { + pnd->iLastError = ECOMTIMEOUT; + return -1; + } res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), &usb_timeout); if (res == -USB_TIMEDOUT) {