From 9eef4d6cec97af8528d1b1cf8cbe1ede99f4f9ba Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 21 May 2015 14:20:16 -0700 Subject: [PATCH] suunto eon steel: clean up size limits and error reporting This is some small cleanup after the whole reply size rewrite. It further improves on the error log reporting a bit, and it undoes the "read exact size" thing introduced in "suunto eon steel: fix file reading special case", because it is no longer necessary. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- src/suunto_eonsteel.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 5713aa4..feb01a3 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -144,8 +144,12 @@ static int receive_packet(suunto_eonsteel_device_t *eon, unsigned char *buffer, /* 5000 = 5s timeout */ rc = libusb_interrupt_transfer(eon->handle, InEndpoint, buf, PACKET_SIZE, &transferred, 5000); - if (rc || transferred != PACKET_SIZE) { - ERROR(eon->base.context, "incomplete read interrupt transfer"); + if (rc) { + ERROR(eon->base.context, "read interrupt transfer failed (%s)", libusb_error_name(rc)); + return -1; + } + if (transferred != PACKET_SIZE) { + ERROR(eon->base.context, "incomplete read interrupt transfer (got %d, expected %d)", transferred, PACKET_SIZE); return -1; } if (buf[0] != 0x3f) { @@ -384,7 +388,7 @@ static int read_file(suunto_eonsteel_device_t *eon, const char *filename, dc_buf put_le32(ask, cmdbuf+4); // Size of read rc = send_receive(eon, FILE_READ_CMD, 8, cmdbuf, - ask+8, result); + sizeof(result), result); if (rc < 0) { ERROR(eon->base.context, "unable to read %s", filename); return -1;