drivers: call adapter_get_required_serial() in jtag_libusb_open()
[openocd.git] / src / jtag / drivers / kitprog.c
index 00d3f5881e5f0a82da588a933343cce206d0e73f..5e2168eea50e227a75282234c26bc7929da80a49 100644 (file)
@@ -114,7 +114,6 @@ struct pending_transfer_result {
        void *buffer;
 };
 
-static char *kitprog_serial;
 static bool kitprog_init_acquire_psoc;
 
 static int pending_transfer_count, pending_queue_len;
@@ -158,7 +157,7 @@ static int kitprog_init(void)
        int retval;
 
        kitprog_handle = malloc(sizeof(struct kitprog));
-       if (kitprog_handle == NULL) {
+       if (!kitprog_handle) {
                LOG_ERROR("Failed to allocate memory");
                return ERROR_FAIL;
        }
@@ -208,14 +207,14 @@ static int kitprog_init(void)
        /* Allocate packet buffers and queues */
        kitprog_handle->packet_size = SWD_MAX_BUFFER_LENGTH;
        kitprog_handle->packet_buffer = malloc(SWD_MAX_BUFFER_LENGTH);
-       if (kitprog_handle->packet_buffer == NULL) {
+       if (!kitprog_handle->packet_buffer) {
                LOG_ERROR("Failed to allocate memory for the packet buffer");
                return ERROR_FAIL;
        }
 
        pending_queue_len = SWD_MAX_BUFFER_LENGTH / 5;
        pending_transfers = malloc(pending_queue_len * sizeof(*pending_transfers));
-       if (pending_transfers == NULL) {
+       if (!pending_transfers) {
                LOG_ERROR("Failed to allocate memory for the SWD transfer queue");
                return ERROR_FAIL;
        }
@@ -230,7 +229,6 @@ static int kitprog_quit(void)
        free(kitprog_handle->packet_buffer);
        free(kitprog_handle->serial);
        free(kitprog_handle);
-       free(kitprog_serial);
        free(pending_transfers);
 
        return ERROR_OK;
@@ -256,7 +254,7 @@ static int kitprog_get_usb_serial(void)
 
        /* Allocate memory for the serial number */
        kitprog_handle->serial = calloc(retval + 1, sizeof(char));
-       if (kitprog_handle->serial == NULL) {
+       if (!kitprog_handle->serial) {
                LOG_ERROR("Failed to allocate memory for the serial number");
                return ERROR_FAIL;
        }
@@ -272,8 +270,7 @@ static int kitprog_usb_open(void)
        const uint16_t vids[] = { VID, 0 };
        const uint16_t pids[] = { PID, 0 };
 
-       if (jtag_libusb_open(vids, pids, kitprog_serial,
-                       &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
+       if (jtag_libusb_open(vids, pids, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
                LOG_ERROR("Failed to open or find the device");
                return ERROR_FAIL;
        }
@@ -285,7 +282,7 @@ static int kitprog_usb_open(void)
        /* Convert the ASCII serial number into a (wchar_t *) */
        size_t len = strlen(kitprog_handle->serial);
        wchar_t *hid_serial = calloc(len + 1, sizeof(wchar_t));
-       if (hid_serial == NULL) {
+       if (!hid_serial) {
                LOG_ERROR("Failed to allocate memory for the serial number");
                return ERROR_FAIL;
        }
@@ -298,7 +295,7 @@ static int kitprog_usb_open(void)
        /* Use HID for the KitBridge interface */
        kitprog_handle->hid_handle = hid_open(VID, PID, hid_serial);
        free(hid_serial);
-       if (kitprog_handle->hid_handle == NULL) {
+       if (!kitprog_handle->hid_handle) {
                LOG_ERROR("Failed to open KitBridge (HID) interface");
                return ERROR_FAIL;
        }
@@ -314,7 +311,7 @@ static int kitprog_usb_open(void)
 
 static void kitprog_usb_close(void)
 {
-       if (kitprog_handle->hid_handle != NULL) {
+       if (kitprog_handle->hid_handle) {
                hid_close(kitprog_handle->hid_handle);
                hid_exit();
        }
@@ -851,22 +848,6 @@ COMMAND_HANDLER(kitprog_handle_acquire_psoc_command)
        return retval;
 }
 
-COMMAND_HANDLER(kitprog_handle_serial_command)
-{
-       if (CMD_ARGC == 1) {
-               kitprog_serial = strdup(CMD_ARGV[0]);
-               if (kitprog_serial == NULL) {
-                       LOG_ERROR("Failed to allocate memory for the serial number");
-                       return ERROR_FAIL;
-               }
-       } else {
-               LOG_ERROR("expected exactly one argument to kitprog_serial <serial-number>");
-               return ERROR_FAIL;
-       }
-
-       return ERROR_OK;
-}
-
 COMMAND_HANDLER(kitprog_handle_init_acquire_psoc_command)
 {
        kitprog_init_acquire_psoc = true;
@@ -900,13 +881,6 @@ static const struct command_registration kitprog_command_handlers[] = {
                .usage = "<cmd>",
                .chain = kitprog_subcommand_handlers,
        },
-       {
-               .name = "kitprog_serial",
-               .handler = &kitprog_handle_serial_command,
-               .mode = COMMAND_CONFIG,
-               .help = "set the serial number of the adapter",
-               .usage = "serial_string",
-       },
        {
                .name = "kitprog_init_acquire_psoc",
                .handler = &kitprog_handle_init_acquire_psoc_command,

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)