From 2ff738dfbaf0f7897af4aff225e25d4acd7789ec Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 11 Feb 2024 17:31:42 +0100 Subject: [PATCH] target/riscv: fix error on exit with uninitialized target riscv_deinit_target() tries to get_target_type() even if the examination failed or was not called at all. dtm_version is not known and an annoying error is printed: Error: [riscv.cpu.0] Unsupported DTM version: -1 Error: [riscv.cpu.0] Could not identify target type. Avoid calling get_target_type() if dtm_version is DTM_DTMCS_VERSION_UNKNOWN. Signed-off-by: Tomas Vanek Change-Id: I48239b1b11561357e845f3a6cb3a8e3b19e35715 --- src/target/riscv/riscv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index c65f99515..739106ffb 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -535,9 +535,12 @@ static void riscv_deinit_target(struct target *target) LOG_TARGET_DEBUG(target, "riscv_deinit_target()"); struct riscv_info *info = target->arch_info; - struct target_type *tt = get_target_type(target); - if (!tt) - LOG_TARGET_ERROR(target, "Could not identify target type."); + struct target_type *tt = NULL; + if (info->dtm_version != DTM_DTMCS_VERSION_UNKNOWN) { + tt = get_target_type(target); + if (!tt) + LOG_TARGET_ERROR(target, "Could not identify target type."); + } if (riscv_flush_registers(target) != ERROR_OK) LOG_TARGET_ERROR(target, "Failed to flush registers. Ignoring this error.");