drivers/cmsis-dap: tidy up buffer access
[fw/openocd] / src / jtag / drivers / cmsis_dap_usb_bulk.c
index 7efea5166689d26339de7fcc377afaddddc2eda4..c9ee53d2effe94085a1d2d53e23f3edd06875c0d 100644 (file)
@@ -360,7 +360,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
                        }
 
                        dap->packet_size = packet_size;
-                       dap->packet_buffer_size = packet_size + REPORT_ID_SIZE;
+                       dap->packet_buffer_size = packet_size;
                        dap->bdata->usb_ctx = ctx;
                        dap->bdata->dev_handle = dev_handle;
                        dap->bdata->ep_out = ep_out;
@@ -374,6 +374,9 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
                                return ERROR_FAIL;
                        }
 
+                       dap->command = dap->packet_buffer;
+                       dap->response = dap->packet_buffer;
+
                        return ERROR_OK;
                }
 
@@ -425,7 +428,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms)
 
        /* skip the first byte that is only used by the HID backend */
        err = libusb_bulk_transfer(dap->bdata->dev_handle, dap->bdata->ep_out,
-                                                       dap->packet_buffer + REPORT_ID_SIZE, txlen - REPORT_ID_SIZE, &transferred, timeout_ms);
+                                                       dap->packet_buffer, txlen, &transferred, timeout_ms);
        if (err) {
                if (err == LIBUSB_ERROR_TIMEOUT) {
                        return ERROR_TIMEOUT_REACHED;
@@ -440,8 +443,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms)
 
 static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
 {
-       unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE;
-       uint8_t *buf = malloc(packet_buffer_size);
+       uint8_t *buf = malloc(pkt_sz);
        if (buf == NULL) {
                LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
                return ERROR_FAIL;
@@ -449,7 +451,10 @@ static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
 
        dap->packet_buffer = buf;
        dap->packet_size = pkt_sz;
-       dap->packet_buffer_size = packet_buffer_size;
+       dap->packet_buffer_size = pkt_sz;
+
+       dap->command = dap->packet_buffer;
+       dap->response = dap->packet_buffer;
 
        return ERROR_OK;
 }