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 ;
0 commit comments