jtag: Fix memory leaks in jtag_tap_free()
[openocd.git] / src / jtag / core.c
index 2f7effe377b690e8b3158706061f9200b2c16581..44aed30ade6b5fecd5128f9fa53a737a6b51457c 100644 (file)
@@ -134,8 +134,6 @@ static int jtag_speed;
 
 static struct jtag_interface *jtag;
 
-const struct swd_driver *swd;
-
 /* configuration */
 struct jtag_interface *jtag_interface;
 
@@ -168,6 +166,9 @@ bool is_jtag_poll_safe(void)
         * It is also implicitly disabled while TRST is active and
         * while SRST is gating the JTAG clock.
         */
+       if (!transport_is_jtag())
+               return jtag_poll;
+
        if (!jtag_poll || jtag_trst != 0)
                return false;
        return jtag_srst == 0 || (jtag_reset_config & RESET_SRST_NO_GATING);
@@ -1177,7 +1178,7 @@ static int jtag_validate_ircapture(void)
        int total_ir_length = 0;
        uint8_t *ir_test = NULL;
        struct scan_field field;
-       int val;
+       uint64_t val;
        int chain_pos = 0;
        int retval;
 
@@ -1236,8 +1237,8 @@ static int jtag_validate_ircapture(void)
                 */
                if (tap->ir_length == 0) {
                        tap->ir_length = 2;
-                       while ((val = buf_get_u32(ir_test, chain_pos, tap->ir_length + 1)) == 1
-                                       && tap->ir_length <= 32) {
+                       while ((val = buf_get_u64(ir_test, chain_pos, tap->ir_length + 1)) == 1
+                                       && tap->ir_length <= 64) {
                                tap->ir_length++;
                        }
                        LOG_WARNING("AUTO %s - use \"... -irlen %d\"",
@@ -1251,25 +1252,23 @@ static int jtag_validate_ircapture(void)
                 * this part of the JTAG spec, so their capture mask/value
                 * attributes might disable this test.
                 */
-               val = buf_get_u32(ir_test, chain_pos, tap->ir_length);
+               val = buf_get_u64(ir_test, chain_pos, tap->ir_length);
                if ((val & tap->ir_capture_mask) != tap->ir_capture_value) {
-                       LOG_ERROR("%s: IR capture error; saw 0x%0*x not 0x%0*x",
+                       LOG_ERROR("%s: IR capture error; saw 0x%0*" PRIx64 " not 0x%0*" PRIx32,
                                jtag_tap_name(tap),
-                               (tap->ir_length + 7) / tap->ir_length,
-                               val,
-                               (tap->ir_length + 7) / tap->ir_length,
-                               (unsigned) tap->ir_capture_value);
+                               (tap->ir_length + 7) / tap->ir_length, val,
+                               (tap->ir_length + 7) / tap->ir_length, tap->ir_capture_value);
 
                        retval = ERROR_JTAG_INIT_FAILED;
                        goto done;
                }
-               LOG_DEBUG("%s: IR capture 0x%0*x", jtag_tap_name(tap),
+               LOG_DEBUG("%s: IR capture 0x%0*" PRIx64, jtag_tap_name(tap),
                        (tap->ir_length + 7) / tap->ir_length, val);
                chain_pos += tap->ir_length;
        }
 
        /* verify the '11' sentinel we wrote is returned at the end */
-       val = buf_get_u32(ir_test, chain_pos, 2);
+       val = buf_get_u64(ir_test, chain_pos, 2);
        if (val != 0x3) {
                char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
 
@@ -1327,12 +1326,13 @@ void jtag_tap_free(struct jtag_tap *tap)
 {
        jtag_unregister_event_callback(&jtag_reset_callback, tap);
 
-       /** @todo is anything missing? no memory leaks please */
-       free((void *)tap->expected);
-       free((void *)tap->expected_ids);
-       free((void *)tap->chip);
-       free((void *)tap->tapname);
-       free((void *)tap->dotted_name);
+       free(tap->expected);
+       free(tap->expected_mask);
+       free(tap->expected_ids);
+       free(tap->cur_instr);
+       free(tap->chip);
+       free(tap->tapname);
+       free(tap->dotted_name);
        free(tap);
 }
 
@@ -1826,6 +1826,8 @@ void adapter_assert_reset(void)
                        jtag_add_reset(0, 1);
        } else if (transport_is_swd())
                swd_add_reset(1);
+       else if (transport_is_cmsis_dap())
+               swd_add_reset(1);  /* FIXME */
        else if (get_current_transport() != NULL)
                LOG_ERROR("reset is not supported on %s",
                        get_current_transport()->name);
@@ -1839,6 +1841,8 @@ void adapter_deassert_reset(void)
                jtag_add_reset(0, 0);
        else if (transport_is_swd())
                swd_add_reset(0);
+       else if (transport_is_cmsis_dap())
+               swd_add_reset(0);  /* FIXME */
        else if (get_current_transport() != NULL)
                LOG_ERROR("reset is not supported on %s",
                        get_current_transport()->name);

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)