Skip to content

Commit 9643379

Browse files
committed
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 <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8684 Reviewed-by: zapb <[email protected]> Tested-by: jenkins
1 parent 8485eb1 commit 9643379

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/transport/transport.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <helper/align.h>
3434
#include <helper/bits.h>
35+
#include <helper/list.h>
3536
#include <helper/log.h>
3637
#include <helper/replacements.h>
3738
#include <transport/transport.h>
@@ -59,7 +60,7 @@ static const struct {
5960
};
6061

6162
/** List of transports registered in OpenOCD. */
62-
static struct transport *transport_list;
63+
static OOCD_LIST_HEAD(transport_list);
6364

6465
/**
6566
* 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)
9899
{
99100
/* name may only identify a known transport;
100101
* caller guarantees session's transport isn't yet set.*/
101-
for (struct transport *t = transport_list; t; t = t->next) {
102+
struct transport *t;
103+
list_for_each_entry(t, &transport_list, lh) {
102104
if (!strcmp(transport_name(t->id), name)) {
103105
int retval = t->select(ctx);
104106
/* select() registers commands specific to this
@@ -193,7 +195,7 @@ int transport_register(struct transport *new_transport)
193195
return ERROR_FAIL;
194196
}
195197

196-
for (t = transport_list; t; t = t->next) {
198+
list_for_each_entry(t, &transport_list, lh) {
197199
if (t->id == new_transport->id) {
198200
LOG_ERROR("transport '%s' already registered",
199201
transport_name(t->id));
@@ -206,8 +208,7 @@ int transport_register(struct transport *new_transport)
206208
transport_name(new_transport->id));
207209

208210
/* splice this into the list */
209-
new_transport->next = transport_list;
210-
transport_list = new_transport;
211+
list_add(&new_transport->lh, &transport_list);
211212
LOG_DEBUG("register '%s' (ID %d)",
212213
transport_name(new_transport->id), new_transport->id);
213214

@@ -270,7 +271,8 @@ COMMAND_HANDLER(handle_transport_list)
270271

271272
command_print(CMD, "The following transports are available:");
272273

273-
for (struct transport *t = transport_list; t; t = t->next)
274+
struct transport *t;
275+
list_for_each_entry(t, &transport_list, lh)
274276
command_print(CMD, "\t%s", transport_name(t->id));
275277

276278
return ERROR_OK;

src/transport/transport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "helper/bits.h"
1616
#include "helper/command.h"
17+
#include "helper/list.h"
1718

1819
#define TRANSPORT_JTAG BIT(0)
1920
#define TRANSPORT_SWD BIT(1)
@@ -84,9 +85,9 @@ struct transport {
8485
int (*override_target)(const char **targetname);
8586

8687
/**
87-
* Transports are stored in a singly linked list.
88+
* Transports are stored in a linked list.
8889
*/
89-
struct transport *next;
90+
struct list_head lh;
9091
};
9192

9293
int transport_register(struct transport *new_transport);

0 commit comments

Comments
 (0)