aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2023-04-15 00:25:54 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2023-04-30 14:52:36 +0000
commit8670ad4caa705c460972badbd0fc28aa98c41866 (patch)
tree0dea5e140abcea3e957f6aebf3f32b90a936573a
parentc1dc7935f78973e89dfe10e5b93238ae3f4eacd3 (diff)
downloadriscv-openocd-8670ad4caa705c460972badbd0fc28aa98c41866.zip
riscv-openocd-8670ad4caa705c460972badbd0fc28aa98c41866.tar.gz
riscv-openocd-8670ad4caa705c460972badbd0fc28aa98c41866.tar.bz2
target/espressif: fix clang report on list use
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
-rw-r--r--src/target/espressif/esp32_apptrace.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/target/espressif/esp32_apptrace.c b/src/target/espressif/esp32_apptrace.c
index dfeb794..291503e 100644
--- a/src/target/espressif/esp32_apptrace.c
+++ b/src/target/espressif/esp32_apptrace.c
@@ -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;
}