]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
transport: use helper/list.h for the list of transports
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 31 Dec 2024 15:29:46 +0000 (16:29 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Thu, 1 May 2025 15:27:02 +0000 (15:27 +0000)
No behavioral change, just use the list's helpers.

Change-Id: I69712648ef77689bfe6acc4811adad7293fb9009
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8684
Reviewed-by: zapb <dev@zapb.de>
Tested-by: jenkins
src/transport/transport.c
src/transport/transport.h

index 59f76ad31dbdc5364e8e83fe789b0fb22fd9ae7d..8a210fe94c63a8d3f01f5c232366beecfe749bed 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <helper/align.h>
 #include <helper/bits.h>
+#include <helper/list.h>
 #include <helper/log.h>
 #include <helper/replacements.h>
 #include <transport/transport.h>
@@ -59,7 +60,7 @@ static const struct {
 };
 
 /** List of transports registered in OpenOCD. */
-static struct transport *transport_list;
+static OOCD_LIST_HEAD(transport_list);
 
 /**
  * Bitmask of transport IDs which the currently selected debug adapter supports.
@@ -98,7 +99,8 @@ static int transport_select(struct command_context *ctx, const char *name)
 {
        /* name may only identify a known transport;
         * caller guarantees session's transport isn't yet set.*/
-       for (struct transport *t = transport_list; t; t = t->next) {
+       struct transport *t;
+       list_for_each_entry(t, &transport_list, lh) {
                if (!strcmp(transport_name(t->id), name)) {
                        int retval = t->select(ctx);
                        /* select() registers commands specific to this
@@ -193,7 +195,7 @@ int transport_register(struct transport *new_transport)
                return ERROR_FAIL;
        }
 
-       for (t = transport_list; t; t = t->next) {
+       list_for_each_entry(t, &transport_list, lh) {
                if (t->id == new_transport->id) {
                        LOG_ERROR("transport '%s' already registered",
                                          transport_name(t->id));
@@ -206,8 +208,7 @@ int transport_register(struct transport *new_transport)
                                  transport_name(new_transport->id));
 
        /* splice this into the list */
-       new_transport->next = transport_list;
-       transport_list = new_transport;
+       list_add(&new_transport->lh, &transport_list);
        LOG_DEBUG("register '%s' (ID %d)",
                          transport_name(new_transport->id), new_transport->id);
 
@@ -270,7 +271,8 @@ COMMAND_HANDLER(handle_transport_list)
 
        command_print(CMD, "The following transports are available:");
 
-       for (struct transport *t = transport_list; t; t = t->next)
+       struct transport *t;
+       list_for_each_entry(t, &transport_list, lh)
                command_print(CMD, "\t%s", transport_name(t->id));
 
        return ERROR_OK;
index f6f0f4f4db5165e30ca1674a9ee322b50d537bac..5445bcf3b24c6ffad6e39ce3a12f596709303c83 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "helper/bits.h"
 #include "helper/command.h"
+#include "helper/list.h"
 
 #define TRANSPORT_JTAG                  BIT(0)
 #define TRANSPORT_SWD                   BIT(1)
@@ -84,9 +85,9 @@ struct transport {
        int (*override_target)(const char **targetname);
 
        /**
-        * Transports are stored in a singly linked list.
+        * Transports are stored in a linked list.
         */
-       struct transport *next;
+       struct list_head lh;
 };
 
 int transport_register(struct transport *new_transport);