target/espressif: fix clang report on list use 08/7608/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Fri, 14 Apr 2023 22:25:54 +0000 (00:25 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 30 Apr 2023 14:52:36 +0000 (14:52 +0000)
It looks like a false positive.
Scan-build considers as possible to:
- have list_empty() return false;
- list_for_each_safe() to not execute any loop, thus not assigning
  a non-NULL value to 'block';
- the NULL pointer 'block' is passed to list_del().
This is not possible because with list_empty(), the loop runs at
least once.

Rewrite the function to simplify the code and making it easier for
scan-build to check it.

This also drops an incorrect use of list_for_each_safe(), where
the 'safe' version was not required.

Change-Id: Ia8b1d221cf9df73db1196e3f51986023dcaf78eb
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 8d1dcf293a0c ("target/espressif: add application tracing functionality over JTAG")
Reviewed-on: https://review.openocd.org/c/openocd/+/7608
Reviewed-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Tested-by: jenkins
src/target/espressif/esp32_apptrace.c

index dfeb794018378fc8b6b0ff93b7a66a0245714067..291503e530e75f11186f1e7638d160d82072ba49 100644 (file)
@@ -356,18 +356,14 @@ static int esp32_apptrace_ready_block_put(struct esp32_apptrace_cmd_ctx *ctx, st
 
 static struct esp32_apptrace_block *esp32_apptrace_ready_block_get(struct esp32_apptrace_cmd_ctx *ctx)
 {
-       struct esp32_apptrace_block *block = NULL;
+       if (list_empty(&ctx->ready_trace_blocks))
+               return NULL;
 
-       if (!list_empty(&ctx->ready_trace_blocks)) {
-               struct list_head *head = &ctx->ready_trace_blocks;
-               struct list_head *tmp, *pos;
+       struct esp32_apptrace_block *block =
+               list_last_entry(&ctx->ready_trace_blocks, struct esp32_apptrace_block, node);
 
-               list_for_each_safe(pos, tmp, head) {
-                       block = list_entry(pos, struct esp32_apptrace_block, node);
-               }
-               /* remove it from ready list */
-               list_del(&block->node);
-       }
+       /* remove it from ready list */
+       list_del(&block->node);
 
        return block;
 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)