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/+/8855

-- gerrit

commit 85031ddb5e5c8481d1903bd4f7593fc71a9a65ef
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Fri Apr 18 17:04:47 2025 +0200

    rtos: rework rtos_types[] and rtos_try_next()
    
    Drop the NULL sentinel at the end of the array and use ARRAY_SIZE()
    to bound the loops.
    Adapt rtos_try_next() to use ARRAY_SIZE().
    
    While there:
    - change to bool the return type of rtos_try_next();
    - move rtos_try_next() to avoid the forward declaration.
    
    Change-Id: I1bee11db943b670789e62f1bebe2509bbef451a0
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 5cac316ed3..26fff166a8 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -13,6 +13,7 @@
 #include "target/target.h"
 #include "helper/log.h"
 #include "helper/binarybuffer.h"
+#include "helper/types.h"
 #include "server/gdb_server.h"
 
 static const struct rtos_type *rtos_types[] = {
@@ -31,11 +32,8 @@ static const struct rtos_type *rtos_types[] = {
        &rtkernel_rtos,
        /* keep this as last, as it always matches with rtos auto */
        &hwthread_rtos,
-       NULL
 };
 
-static int rtos_try_next(struct target *target);
-
 int rtos_smp_init(struct target *target)
 {
        if (target->rtos->type->smp_init)
@@ -116,12 +114,12 @@ int rtos_create(struct command_invocation *cmd, struct 
target *target,
                return os_alloc(target, rtos_types[0]);
        }
 
-       for (int x = 0; rtos_types[x]; x++)
+       for (size_t x = 0; x < ARRAY_SIZE(rtos_types); x++)
                if (strcmp(rtos_name, rtos_types[x]->name) == 0)
                        return os_alloc_create(target, rtos_types[x]);
 
        char *all = NULL;
-       for (int x = 0; rtos_types[x]; x++) {
+       for (size_t x = 0; x < ARRAY_SIZE(rtos_types); x++) {
                char *prev = all;
                if (all)
                        all = alloc_printf("%s, %s", all, rtos_types[x]->name);
@@ -155,6 +153,29 @@ int gdb_thread_packet(struct connection *connection, char 
const *packet, int pac
        return target->rtos->gdb_thread_packet(connection, packet, packet_size);
 }
 
+static bool rtos_try_next(struct target *target)
+{
+       struct rtos *os = target->rtos;
+
+       if (!os)
+               return false;
+
+       for (size_t x = 0; x < ARRAY_SIZE(rtos_types) - 1; x++) {
+               if (os->type == rtos_types[x]) {
+                       /* Use next RTOS in the list */
+                       os->type = rtos_types[x + 1];
+
+                       free(os->symbols);
+                       os->symbols = NULL;
+
+                       return true;
+               }
+       }
+
+       /* No next RTOS to try */
+       return false;
+}
+
 static struct symbol_table_elem *find_symbol(const struct rtos *os, const char 
*symbol)
 {
        struct symbol_table_elem *s;
@@ -667,28 +688,6 @@ int rtos_generic_stack_read(struct target *target,
        return ERROR_OK;
 }
 
-static int rtos_try_next(struct target *target)
-{
-       struct rtos *os = target->rtos;
-       const struct rtos_type **type = rtos_types;
-
-       if (!os)
-               return 0;
-
-       while (*type && os->type != *type)
-               type++;
-
-       if (!*type || !*(++type))
-               return 0;
-
-       os->type = *type;
-
-       free(os->symbols);
-       os->symbols = NULL;
-
-       return 1;
-}
-
 int rtos_update_threads(struct target *target)
 {
        if ((target->rtos) && (target->rtos->type))

-- 

Reply via email to