|
From: openocd-gerrit <ope...@us...> - 2026-05-17 20:55:28
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 2acd694e3c6d7e3fb11d4ad92b4440f2b51db2d3 (commit)
from 2fb8a4752ac59c134209ffec497ba96e3f51f520 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2acd694e3c6d7e3fb11d4ad92b4440f2b51db2d3
Author: Marc Schink <de...@za...>
Date: Mon Aug 4 12:57:05 2025 +0200
helper: Use proper return values for duration_{start,measure}
The return value of gettimeofday() is used directly as return value of
duration_{start,measure}, but checked inconsistently against 0 or
ERROR_OK. Use proper return values and make the code more consistent.
While at it, remove unnecessary parentheses to make checkpatch happy.
Change-Id: I6bb8418887b09c7510d2f79e4ec7e5389f59849b
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9286
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index add7df437..bbf8a4fb0 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -275,7 +275,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command)
if (retval == ERROR_OK)
retval = flash_erase_address_range(target, do_pad, address, length);
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "erased address " TARGET_ADDR_FMT " (length %" PRIu32 ")"
" in %fs (%0.3f KiB/s)", address, length,
duration_elapsed(&bench), duration_kbps(&bench, length));
@@ -323,7 +323,7 @@ COMMAND_HANDLER(handle_flash_erase_command)
retval = flash_driver_erase(p, first, last);
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "erased sectors %" PRIu32 " "
"through %" PRIu32 " on flash bank %u "
"in %fs", first, last, p->bank_number, duration_elapsed(&bench));
@@ -449,7 +449,7 @@ COMMAND_HANDLER(handle_flash_write_image_command)
return retval;
}
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "wrote %" PRIu32 " bytes from file %s "
"in %fs (%0.3f KiB/s)", written, CMD_ARGV[0],
duration_elapsed(&bench), duration_kbps(&bench, written));
@@ -501,7 +501,7 @@ COMMAND_HANDLER(handle_flash_verify_image_command)
return retval;
}
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "verified %" PRIu32 " bytes from file %s "
"in %fs (%0.3f KiB/s)", verified, CMD_ARGV[0],
duration_elapsed(&bench), duration_kbps(&bench, verified));
@@ -655,7 +655,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
ptr += wordsize;
}
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "wrote %" PRIu32 " bytes to " TARGET_ADDR_FMT
" in %fs (%0.3f KiB/s)", size_bytes, address,
duration_elapsed(&bench), duration_kbps(&bench, size_bytes));
@@ -950,7 +950,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
free(buffer);
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "wrote %zu bytes from file %s to flash bank %u"
" at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)",
length, CMD_ARGV[1], bank->bank_number, offset,
diff --git a/src/helper/time_support.c b/src/helper/time_support.c
index dda3cb3e4..46fb17246 100644
--- a/src/helper/time_support.c
+++ b/src/helper/time_support.c
@@ -15,6 +15,8 @@
#include "config.h"
#endif
+#include <helper/log.h>
+
#include "time_support.h"
/* calculate difference between two struct timeval values */
@@ -68,16 +70,21 @@ int timeval_compare(const struct timeval *x, const struct timeval *y)
int duration_start(struct duration *duration)
{
- return gettimeofday(&duration->start, NULL);
+ if (gettimeofday(&duration->start, NULL) != 0)
+ return ERROR_FAIL;
+
+ return ERROR_OK;
}
int duration_measure(struct duration *duration)
{
struct timeval end;
- int retval = gettimeofday(&end, NULL);
- if (retval == 0)
- timeval_subtract(&duration->elapsed, &end, &duration->start);
- return retval;
+ if (gettimeofday(&end, NULL) != 0)
+ return ERROR_FAIL;
+
+ timeval_subtract(&duration->elapsed, &end, &duration->start);
+
+ return ERROR_OK;
}
float duration_elapsed(const struct duration *duration)
diff --git a/src/target/espressif/esp32_apptrace.c b/src/target/espressif/esp32_apptrace.c
index 307096019..77201ae90 100644
--- a/src/target/espressif/esp32_apptrace.c
+++ b/src/target/espressif/esp32_apptrace.c
@@ -488,7 +488,7 @@ int esp32_apptrace_cmd_ctx_init(struct esp32_apptrace_cmd_ctx *cmd_ctx, struct c
cmd_ctx->stats.min_blk_read_time = 1000000.0;
cmd_ctx->stats.min_blk_proc_time = 1000000.0;
}
- if (duration_start(&cmd_ctx->idle_time) != 0) {
+ if (duration_start(&cmd_ctx->idle_time) != ERROR_OK) {
command_print(cmd, "Failed to start idle time measurement!");
esp32_apptrace_cmd_ctx_cleanup(cmd_ctx);
return ERROR_FAIL;
@@ -905,7 +905,7 @@ static int esp32_apptrace_process_data(struct esp32_apptrace_cmd_ctx *ctx,
/* check for stop condition */
if (ctx->tot_len > cmd_data->skip_len && (ctx->tot_len - cmd_data->skip_len >= cmd_data->max_len)) {
ctx->running = 0;
- if (duration_measure(&ctx->read_time) != 0) {
+ if (duration_measure(&ctx->read_time) != ERROR_OK) {
LOG_ERROR("Failed to stop trace read time measure!");
return ERROR_FAIL;
}
@@ -1005,7 +1005,7 @@ static int esp32_apptrace_check_connection(struct esp32_apptrace_cmd_ctx *ctx)
}
if (ctx->stop_tmo != -1.0) {
/* re-start idle time measurement */
- if (duration_start(&ctx->idle_time) != 0) {
+ if (duration_start(&ctx->idle_time) != ERROR_OK) {
LOG_ERROR("Failed to re-start idle time measure!");
return ERROR_FAIL;
}
@@ -1082,7 +1082,7 @@ static int esp32_apptrace_poll(void *priv)
ctx->last_blk_id = max_block_id;
}
if (ctx->stop_tmo != -1.0) {
- if (duration_measure(&ctx->idle_time) != 0) {
+ if (duration_measure(&ctx->idle_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to measure idle time!");
return ERROR_FAIL;
@@ -1102,7 +1102,7 @@ static int esp32_apptrace_poll(void *priv)
return ERROR_FAIL;
}
if (ctx->tot_len == 0) {
- if (duration_start(&ctx->read_time) != 0) {
+ if (duration_start(&ctx->read_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to start trace read time measurement!");
return ERROR_FAIL;
@@ -1116,7 +1116,7 @@ static int esp32_apptrace_poll(void *priv)
}
if (s_time_stats_enable) {
/* read block */
- if (duration_start(&blk_proc_time) != 0) {
+ if (duration_start(&blk_proc_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to start block read time measurement!");
return ERROR_FAIL;
@@ -1136,7 +1136,7 @@ static int esp32_apptrace_poll(void *priv)
block->data_len = target_state[fired_target_num].data_len;
ctx->raw_tot_len += block->data_len;
if (s_time_stats_enable) {
- if (duration_measure(&blk_proc_time) != 0) {
+ if (duration_measure(&blk_proc_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to measure block read time!");
return ERROR_FAIL;
@@ -1148,7 +1148,7 @@ static int esp32_apptrace_poll(void *priv)
if (brt < ctx->stats.min_blk_read_time)
ctx->stats.min_blk_read_time = brt;
- if (duration_start(&blk_proc_time) != 0) {
+ if (duration_start(&blk_proc_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to start block proc time measurement!");
return ERROR_FAIL;
@@ -1194,14 +1194,14 @@ static int esp32_apptrace_poll(void *priv)
}
if (ctx->stop_tmo != -1.0) {
/* start idle time measurement */
- if (duration_start(&ctx->idle_time) != 0) {
+ if (duration_start(&ctx->idle_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to start idle time measure!");
return ERROR_FAIL;
}
}
if (s_time_stats_enable) {
- if (duration_measure(&blk_proc_time) != 0) {
+ if (duration_measure(&blk_proc_time) != ERROR_OK) {
ctx->running = 0;
LOG_ERROR("Failed to stop block proc time measure!");
return ERROR_FAIL;
@@ -1223,7 +1223,7 @@ static inline bool is_sysview_mode(int mode)
static void esp32_apptrace_cmd_stop(struct esp32_apptrace_cmd_ctx *ctx)
{
- if (duration_measure(&ctx->read_time) != 0)
+ if (duration_measure(&ctx->read_time) != ERROR_OK)
LOG_ERROR("Failed to stop trace read time measurement!");
int res = target_unregister_timer_callback(esp32_apptrace_poll, ctx);
if (res != ERROR_OK)
@@ -1362,7 +1362,7 @@ static int esp32_sysview_stop(struct esp32_apptrace_cmd_ctx *ctx)
}
/* wait for block switch (command sent), so we can disconnect from targets */
old_block_id = target_state[fired_target_num].block_id;
- if (duration_start(&wait_time) != 0) {
+ if (duration_start(&wait_time) != ERROR_OK) {
LOG_ERROR("Failed to start trace stop timeout measurement!");
return ERROR_FAIL;
}
@@ -1418,7 +1418,7 @@ static int esp32_sysview_stop(struct esp32_apptrace_cmd_ctx *ctx)
old_block_id = target_state[fired_target_num].block_id;
}
}
- if (duration_measure(&wait_time) != 0) {
+ if (duration_measure(&wait_time) != ERROR_OK) {
LOG_ERROR("Failed to start trace stop timeout measurement!");
return ERROR_FAIL;
}
@@ -1532,7 +1532,7 @@ static int esp32_cmd_apptrace_generic(struct command_invocation *cmd, int mode,
esp32_apptrace_cmd_stop(&s_at_cmd_ctx);
return ERROR_OK;
} else if (strcmp(argv[0], "status") == 0) {
- if (s_at_cmd_ctx.running && duration_measure(&s_at_cmd_ctx.read_time) != 0)
+ if (s_at_cmd_ctx.running && duration_measure(&s_at_cmd_ctx.read_time) != ERROR_OK)
LOG_ERROR("Failed to measure trace read time!");
esp32_apptrace_print_stats(&s_at_cmd_ctx);
return ERROR_OK;
diff --git a/src/target/espressif/esp32_sysview.c b/src/target/espressif/esp32_sysview.c
index 2fe215778..d8eda0773 100644
--- a/src/target/espressif/esp32_sysview.c
+++ b/src/target/espressif/esp32_sysview.c
@@ -545,7 +545,7 @@ int esp32_sysview_process_data(struct esp32_apptrace_cmd_ctx *ctx,
if (ctx->tot_len > cmd_data->apptrace.skip_len &&
(ctx->tot_len - cmd_data->apptrace.skip_len >= cmd_data->apptrace.max_len)) {
ctx->running = 0;
- if (duration_measure(&ctx->read_time) != 0) {
+ if (duration_measure(&ctx->read_time) != ERROR_OK) {
LOG_ERROR("Failed to stop trace read time measure!");
return ERROR_FAIL;
}
diff --git a/src/target/espressif/esp_algorithm.c b/src/target/espressif/esp_algorithm.c
index 79f610b92..ddb557583 100644
--- a/src/target/espressif/esp_algorithm.c
+++ b/src/target/espressif/esp_algorithm.c
@@ -307,7 +307,7 @@ int esp_algorithm_load_func_image(struct target *target, struct esp_algorithm_ru
if (!run || !run->hw)
return ERROR_FAIL;
- if (duration_start(&algo_time) != 0) {
+ if (duration_start(&algo_time) != ERROR_OK) {
LOG_ERROR("Failed to start algo time measurement!");
return ERROR_FAIL;
}
@@ -486,7 +486,7 @@ int esp_algorithm_load_func_image(struct target *target, struct esp_algorithm_ru
run->stub.stack_addr = run->stub.stack->address + run->stack_size;
}
- if (duration_measure(&algo_time) != 0) {
+ if (duration_measure(&algo_time) != ERROR_OK) {
LOG_ERROR("Failed to stop algo run measurement!");
retval = ERROR_FAIL;
goto _on_error;
@@ -536,7 +536,7 @@ int esp_algorithm_load_onboard_func(struct target *target, target_addr_t func_ad
if (!run || !run->hw)
return ERROR_FAIL;
- if (duration_start(&algo_time) != 0) {
+ if (duration_start(&algo_time) != ERROR_OK) {
LOG_ERROR("Failed to start algo time measurement!");
return ERROR_FAIL;
}
@@ -572,7 +572,7 @@ int esp_algorithm_load_onboard_func(struct target *target, target_addr_t func_ad
}
}
- if (duration_measure(&algo_time) != 0) {
+ if (duration_measure(&algo_time) != ERROR_OK) {
LOG_ERROR("Failed to stop algo run measurement!");
return ERROR_FAIL;
}
diff --git a/src/target/target.c b/src/target/target.c
index 154891d0f..d0776834e 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3630,7 +3630,7 @@ COMMAND_HANDLER(handle_load_image_command)
free(buffer);
}
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "downloaded %" PRIu32 " bytes "
"in %fs (%0.3f KiB/s)", image_size,
duration_elapsed(&bench), duration_kbps(&bench, image_size));
@@ -3687,7 +3687,7 @@ COMMAND_HANDLER(handle_dump_image_command)
free(buffer);
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
size_t filesize;
retval = fileio_size(fileio, &filesize);
if (retval != ERROR_OK)
@@ -3838,7 +3838,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver
done:
if (diffs > 0)
retval = ERROR_FAIL;
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "verified %" PRIu32 " bytes "
"in %fs (%0.3f KiB/s)", image_size,
duration_elapsed(&bench), duration_kbps(&bench, image_size));
@@ -6160,7 +6160,7 @@ COMMAND_HANDLER(handle_fast_load_image_command)
free(buffer);
}
- if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) {
+ if (retval == ERROR_OK && duration_measure(&bench) == ERROR_OK) {
command_print(CMD, "Loaded %" PRIu32 " bytes "
"in %fs (%0.3f KiB/s)", image_size,
duration_elapsed(&bench), duration_kbps(&bench, image_size));
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/tcl.c | 12 ++++++------
src/helper/time_support.c | 17 ++++++++++++-----
src/target/espressif/esp32_apptrace.c | 28 ++++++++++++++--------------
src/target/espressif/esp32_sysview.c | 2 +-
src/target/espressif/esp_algorithm.c | 8 ++++----
src/target/target.c | 8 ++++----
6 files changed, 41 insertions(+), 34 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|