cmsis-dap: don't update the packet size across backends.
[openocd.git] / src / jtag / drivers / cmsis_dap.c
index fd565398ff9b3876fc85d3f6ae16c1462b1e9b4a..7a5acc3140c2bb1dab7996a7d0430214a4024833 100644 (file)
@@ -225,16 +225,12 @@ static int cmsis_dap_open(void)
 {
        const struct cmsis_dap_backend *backend = NULL;
 
-       struct cmsis_dap *dap = malloc(sizeof(struct cmsis_dap));
+       struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap));
        if (dap == NULL) {
                LOG_ERROR("unable to allocate memory");
                return ERROR_FAIL;
        }
 
-       dap->caps = 0;
-       dap->mode = 0;
-       dap->packet_size = 0; /* initialized by backend */
-
        if (cmsis_dap_backend >= 0) {
                /* Use forced backend */
                backend = cmsis_dap_backends[cmsis_dap_backend];
@@ -257,17 +253,7 @@ static int cmsis_dap_open(void)
                return ERROR_FAIL;
        }
 
-       assert(dap->packet_size > 0);
-
        dap->backend = backend;
-       dap->packet_buffer = malloc(dap->packet_size);
-
-       if (dap->packet_buffer == NULL) {
-               LOG_ERROR("unable to allocate memory");
-               dap->backend->close(dap);
-               free(dap);
-               return ERROR_FAIL;
-       }
 
        cmsis_dap_handle = dap;
 
@@ -929,24 +915,20 @@ static int cmsis_dap_init(void)
 
        if (data[0] == 2) {  /* short */
                uint16_t pkt_sz = data[1] + (data[2] << 8);
+               if (pkt_sz != cmsis_dap_handle->packet_size) {
 
-               /* 4 bytes of command header + 5 bytes per register
-                * write. For bulk read sequences just 4 bytes are
-                * needed per transfer, so this is suboptimal. */
-               pending_queue_len = (pkt_sz - 4) / 5;
-
-               if (cmsis_dap_handle->packet_size != pkt_sz + 1) {
-                       /* reallocate buffer */
-                       cmsis_dap_handle->packet_size = pkt_sz + 1;
-                       cmsis_dap_handle->packet_buffer = realloc(cmsis_dap_handle->packet_buffer,
-                                       cmsis_dap_handle->packet_size);
-                       if (cmsis_dap_handle->packet_buffer == NULL) {
-                               LOG_ERROR("unable to reallocate memory");
-                               return ERROR_FAIL;
-                       }
-               }
+                       /* 4 bytes of command header + 5 bytes per register
+                        * write. For bulk read sequences just 4 bytes are
+                        * needed per transfer, so this is suboptimal. */
+                       pending_queue_len = (pkt_sz - 4) / 5;
 
-               LOG_DEBUG("CMSIS-DAP: Packet Size = %" PRId16, pkt_sz);
+                       free(cmsis_dap_handle->packet_buffer);
+                       retval = cmsis_dap_handle->backend->packet_buffer_alloc(cmsis_dap_handle, pkt_sz);
+                       if (retval != ERROR_OK)
+                               return retval;
+
+                       LOG_DEBUG("CMSIS-DAP: Packet Size = %" PRIu16, pkt_sz);
+               }
        }
 
        /* INFO_ID_PKT_CNT - byte */

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)