From: Antonio Borneo Date: Tue, 31 Dec 2024 15:29:46 +0000 (+0100) Subject: transport: use helper/list.h for the list of transports X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9643379d30fee381e92200ef9ed0caaeae580dad;p=users%2Fborneoa%2Fopenocd-next.git transport: use helper/list.h for the list of transports No behavioral change, just use the list's helpers. Change-Id: I69712648ef77689bfe6acc4811adad7293fb9009 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8684 Reviewed-by: zapb Tested-by: jenkins --- diff --git a/src/transport/transport.c b/src/transport/transport.c index 59f76ad31..8a210fe94 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/src/transport/transport.h b/src/transport/transport.h index f6f0f4f4d..5445bcf3b 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -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);