Check return result of hfa clear readbuf to minimise error messages on device failure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/driver-hashfast.c b/driver-hashfast.c
index d9834ac..8bf5eb5 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -458,9 +458,9 @@ tryagain:
return true;
}
-static void hfa_clear_readbuf(struct cgpu_info *hashfast)
+static bool hfa_clear_readbuf(struct cgpu_info *hashfast)
{
- int amount, ret;
+ int amount, ret = 0;
char buf[512];
do {
@@ -468,6 +468,10 @@ static void hfa_clear_readbuf(struct cgpu_info *hashfast)
break;
ret = usb_read(hashfast, buf, 512, &amount, C_HF_CLEAR_READ);
} while (!ret || amount);
+
+ if (ret && ret != LIBUSB_ERROR_TIMEOUT)
+ return false;
+ return true;
}
static bool hfa_send_shutdown(struct cgpu_info *hashfast)
@@ -480,7 +484,8 @@ static bool hfa_send_shutdown(struct cgpu_info *hashfast)
* discard any work it thinks is in flight for a cleaner restart. */
if (!hfa_send_frame(hashfast, HF_USB_CMD(OP_WORK_RESTART), 0, (uint8_t *)NULL, 0))
return ret;
- hfa_clear_readbuf(hashfast);
+ if (!hfa_clear_readbuf(hashfast))
+ return ret;
if (hfa_send_frame(hashfast, HF_USB_CMD(OP_USB_SHUTDOWN), 0, NULL, 0)) {
/* Wait to allow device to properly shut down. */
cgsleep_ms(1000);
@@ -542,7 +547,8 @@ static bool hfa_initialise(struct cgpu_info *hashfast)
if (hashfast->usbinfo.nodev)
return false;
- hfa_clear_readbuf(hashfast);
+ if (!hfa_clear_readbuf(hashfast))
+ return false;
err = usb_transfer(hashfast, 0, 9, 1, 0, C_ATMEL_RESET);
if (!err)
@@ -1270,8 +1276,9 @@ static bool hfa_running_reset(struct cgpu_info *hashfast, struct hashfast_info *
* inhibit the read thread from reading our response to the
* OP_USB_INIT */
mutex_lock(&info->rlock);
- hfa_clear_readbuf(hashfast);
- ret = hfa_reset(hashfast, info);
+ ret = hfa_clear_readbuf(hashfast);
+ if (ret)
+ ret = hfa_reset(hashfast, info);
mutex_unlock(&info->rlock);
out: