This is an automated email from Gerrit. "Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8684
-- gerrit commit 73efd5a56fccaefcb6b79c8eed8c5d9146053704 Author: Antonio Borneo <borneo.anto...@gmail.com> Date: Tue Dec 31 16:29:46 2024 +0100 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 <borneo.anto...@gmail.com> diff --git a/src/transport/transport.c b/src/transport/transport.c index 76eb11cd7f..013bf0b27a 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -31,6 +31,7 @@ */ #include <helper/bits.h> +#include <helper/list.h> #include <helper/log.h> #include <helper/replacements.h> #include <transport/transport.h> @@ -55,7 +56,7 @@ static const char * const transport_name[] = { }; /** List of transports registered in OpenOCD. */ -static struct transport *transport_list; +static LIST_HEAD(transport_list); /** * NULL-terminated Vector of IDs of transports which the @@ -76,7 +77,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 @@ -164,7 +166,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]); @@ -177,8 +179,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); @@ -237,7 +238,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 87437a070e..a231f2b924 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -13,6 +13,7 @@ #endif #include "helper/command.h" +#include "helper/list.h" enum transport_id { TRANSPORT_UNKNOWN, @@ -82,9 +83,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); --