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.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8684
Reviewed-by: zapb <dev@zapb.de>
Tested-by: jenkins
This commit is contained in:
Antonio Borneo
2024-12-31 16:29:46 +01:00
parent 8485eb1415
commit 9643379d30
2 changed files with 11 additions and 8 deletions

View 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;

View 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);