aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/drivers/osbdm.c
diff options
context:
space:
mode:
authorOleksij Rempel <o.rempel@pengutronix.de>2018-07-05 13:42:14 +0200
committerOleksij Rempel <linux@rempel-privat.de>2020-01-22 05:33:31 +0000
commitd612baacaa3fef549c446053089867d7b134ccfd (patch)
treeef772f2e9454d1330b1429a9826993f5f0339782 /src/jtag/drivers/osbdm.c
parentf98099507f509db9a18c70365490a6b9f67108db (diff)
jtag_libusb_bulk_read|write: return error code instead of size
A USB bulk write/read operation may fail with different errors: LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates transferred) LIBUSB_ERROR_PIPE if the endpoint halted LIBUSB_ERROR_OVERFLOW if the device offered more data, see Packets and overflows LIBUSB_ERROR_NO_DEVICE if the device has been disconnected another LIBUSB_ERROR code on other failures Current OpenOCD code is using the transfer size based error detection. Which may not always work. For example for LIBUSB_ERROR_OVERFLOW as libusb documentation says: "Problems may occur if the device attempts to send more data than can fit in the buffer. libusb reports LIBUSB_TRANSFER_OVERFLOW for this condition but other behaviour is largely undefined: actual_length may or may not be accurate, the chunk of data that can fit in the buffer (before overflow) may or may not have been transferred." This patch is refactoring code to use actual error return value for error detection instead of size. Change-Id: Iec0798438ca7b5c76e2e2912af21d9aa76ee0217 Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Reviewed-on: http://openocd.zylin.com/4590 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Diffstat (limited to 'src/jtag/drivers/osbdm.c')
-rw-r--r--src/jtag/drivers/osbdm.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/jtag/drivers/osbdm.c b/src/jtag/drivers/osbdm.c
index ed89a794..9a570b09 100644
--- a/src/jtag/drivers/osbdm.c
+++ b/src/jtag/drivers/osbdm.c
@@ -144,10 +144,12 @@ static struct osbdm osbdm_context;
static int osbdm_send_and_recv(struct osbdm *osbdm)
{
/* Send request */
- int count = jtag_libusb_bulk_write(osbdm->devh, OSBDM_USB_EP_WRITE,
- (char *)osbdm->buffer, osbdm->count, OSBDM_USB_TIMEOUT);
+ int count, ret;
- if (count != osbdm->count) {
+ ret = jtag_libusb_bulk_write(osbdm->devh, OSBDM_USB_EP_WRITE,
+ (char *)osbdm->buffer, osbdm->count,
+ OSBDM_USB_TIMEOUT, &count);
+ if (ret || count != osbdm->count) {
LOG_ERROR("OSBDM communication error: can't write");
return ERROR_FAIL;
}
@@ -156,13 +158,12 @@ static int osbdm_send_and_recv(struct osbdm *osbdm)
uint8_t cmd_saved = osbdm->buffer[0];
/* Reading answer */
- osbdm->count = jtag_libusb_bulk_read(osbdm->devh, OSBDM_USB_EP_READ,
- (char *)osbdm->buffer, OSBDM_USB_BUFSIZE, OSBDM_USB_TIMEOUT);
-
+ ret = jtag_libusb_bulk_read(osbdm->devh, OSBDM_USB_EP_READ,
+ (char *)osbdm->buffer, OSBDM_USB_BUFSIZE,
+ OSBDM_USB_TIMEOUT, &osbdm->count);
/* Now perform basic checks for data sent by BDM device
*/
-
- if (osbdm->count < 0) {
+ if (ret) {
LOG_ERROR("OSBDM communication error: can't read");
return ERROR_FAIL;
}