From 6f5259db05b262faac84a58bf3d7c3ddff394281 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 16 May 2021 13:53:10 +0200 Subject: riscv: prefer ARRAY_SIZE() to DIM() OpenOCD already defines the macro ARRAY_SIZE, while riscv code uses a local macro DIM. Prefer using the macro ARRAY_SIZE() instead of DIM(). Not all the riscv code has been upstreamed, yes; this patch only covers the code not upstreamed. Change-Id: Ie3e411280f76bc798f1d51c2574cfec148ee0d0d Signed-off-by: Antonio Borneo --- src/target/riscv/riscv-013.c | 6 +++--- src/target/riscv/riscv.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/target') diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 80fe5e5..b6777cb 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2159,7 +2159,7 @@ static int sample_memory_bus_v1(struct target *target, const unsigned repeat = 5; unsigned enabled_count = 0; - for (unsigned i = 0; i < DIM(config->bucket); i++) { + for (unsigned i = 0; i < ARRAY_SIZE(config->bucket); i++) { if (config->bucket[i].enabled) enabled_count++; } @@ -2176,7 +2176,7 @@ static int sample_memory_bus_v1(struct target *target, unsigned result_bytes = 0; for (unsigned n = 0; n < repeat; n++) { - for (unsigned i = 0; i < DIM(config->bucket); i++) { + for (unsigned i = 0; i < ARRAY_SIZE(config->bucket); i++) { if (config->bucket[i].enabled) { if (!sba_supports_access(target, config->bucket[i].size_bytes)) { LOG_ERROR("Hardware does not support SBA access for %d-byte memory sampling.", @@ -2244,7 +2244,7 @@ static int sample_memory_bus_v1(struct target *target, unsigned read = 0; for (unsigned n = 0; n < repeat; n++) { - for (unsigned i = 0; i < DIM(config->bucket); i++) { + for (unsigned i = 0; i < ARRAY_SIZE(config->bucket); i++) { if (config->bucket[i].enabled) { assert(i < RISCV_SAMPLE_BUF_TIMESTAMP_BEFORE); uint64_t value = 0; diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index d350e01..20f9e2f 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -2076,7 +2076,7 @@ int sample_memory(struct target *target) /* Default slow path. */ while (timeval_ms() - start < TARGET_DEFAULT_POLLING_INTERVAL) { - for (unsigned i = 0; i < DIM(r->sample_config.bucket); i++) { + for (unsigned i = 0; i < ARRAY_SIZE(r->sample_config.bucket); i++) { if (r->sample_config.bucket[i].enabled && r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) { assert(i < RISCV_SAMPLE_BUF_TIMESTAMP_BEFORE); @@ -2866,7 +2866,7 @@ COMMAND_HANDLER(handle_memory_sample_command) if (CMD_ARGC == 0) { command_print(CMD, "Memory sample configuration for %s:", target_name(target)); - for (unsigned i = 0; i < DIM(r->sample_config.bucket); i++) { + for (unsigned i = 0; i < ARRAY_SIZE(r->sample_config.bucket); i++) { if (r->sample_config.bucket[i].enabled) { command_print(CMD, "bucket %d; address=0x%" TARGET_PRIxADDR "; size=%d", i, r->sample_config.bucket[i].address, @@ -2885,8 +2885,8 @@ COMMAND_HANDLER(handle_memory_sample_command) uint32_t bucket; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bucket); - if (bucket > DIM(r->sample_config.bucket)) { - LOG_ERROR("Max bucket number is %d.", (unsigned) DIM(r->sample_config.bucket)); + if (bucket > ARRAY_SIZE(r->sample_config.bucket)) { + LOG_ERROR("Max bucket number is %d.", (unsigned) ARRAY_SIZE(r->sample_config.bucket)); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -2964,7 +2964,7 @@ COMMAND_HANDLER(handle_dump_sample_buf_command) uint32_t timestamp = buf_get_u32(r->sample_buf.buf + i, 0, 32); i += 4; command_print(CMD, "timestamp after: %u", timestamp); - } else if (command < DIM(r->sample_config.bucket)) { + } else if (command < ARRAY_SIZE(r->sample_config.bucket)) { command_print_sameline(CMD, "0x%" TARGET_PRIxADDR ": ", r->sample_config.bucket[command].address); if (r->sample_config.bucket[command].size_bytes == 4) { -- cgit v1.1