jtag_libusb_bulk_read|write: return error code instead of size
[openocd.git] / src / jtag / drivers / stlink_usb.c
index 5c904d4ffb6a94b9aabf73b5a76d2b9b7a7db67a..8e4493ed89560e245fcee61ec504beca77ac0628 100644 (file)
@@ -531,14 +531,16 @@ static int jtag_libusb_bulk_transfer_n(
 static int stlink_usb_xfer_v1_get_status(void *handle)
 {
        struct stlink_usb_handle_s *h = handle;
+       int tr, ret;
 
        assert(handle != NULL);
 
        /* read status */
        memset(h->cmdbuf, 0, STLINK_SG_SIZE);
 
-       if (jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)h->cmdbuf,
-                       13, STLINK_READ_TIMEOUT) != 13)
+       ret = jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)h->cmdbuf, 13,
+                                   STLINK_READ_TIMEOUT, &tr);
+       if (ret || tr != 13)
                return ERROR_FAIL;
 
        uint32_t t1;
@@ -602,23 +604,26 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int
 static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size)
 {
        struct stlink_usb_handle_s *h = handle;
+       int tr, ret;
 
        assert(handle != NULL);
 
-       if (jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)h->cmdbuf, cmdsize,
-                       STLINK_WRITE_TIMEOUT) != cmdsize) {
+       ret = jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)h->cmdbuf,
+                                    cmdsize, STLINK_WRITE_TIMEOUT, &tr);
+       if (ret || tr != cmdsize)
                return ERROR_FAIL;
-       }
 
        if (h->direction == h->tx_ep && size) {
-               if (jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)buf,
-                               size, STLINK_WRITE_TIMEOUT) != size) {
+               ret = jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)buf,
+                                            size, STLINK_WRITE_TIMEOUT, &tr);
+               if (ret || tr != size) {
                        LOG_DEBUG("bulk write failed");
                        return ERROR_FAIL;
                }
        } else if (h->direction == h->rx_ep && size) {
-               if (jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)buf,
-                               size, STLINK_READ_TIMEOUT) != size) {
+               ret = jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)buf,
+                                           size, STLINK_READ_TIMEOUT, &tr);
+               if (ret || tr != size) {
                        LOG_DEBUG("bulk read failed");
                        return ERROR_FAIL;
                }
@@ -840,13 +845,15 @@ static int stlink_cmd_allow_retry(void *handle, const uint8_t *buf, int size)
 static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size)
 {
        struct stlink_usb_handle_s *h = handle;
+       int tr, ret;
 
        assert(handle != NULL);
 
        assert(h->version.flags & STLINK_F_HAS_TRACE);
 
-       if (jtag_libusb_bulk_read(h->fd, h->trace_ep, (char *)buf,
-                       size, STLINK_READ_TIMEOUT) != size) {
+       ret = jtag_libusb_bulk_read(h->fd, h->trace_ep, (char *)buf, size,
+                                   STLINK_READ_TIMEOUT, &tr);
+       if (ret || tr != size) {
                LOG_ERROR("bulk trace read failed");
                return ERROR_FAIL;
        }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)