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 <vanekt@fbl.cz>
Change-Id: I48239b1b11561357e845f3a6cb3a8e3b19e35715
This commit is contained in:
Tomas Vanek 2024-02-11 17:31:42 +01:00
parent b7e7a030c1
commit 2ff738dfba
1 changed files with 6 additions and 3 deletions

View File

@ -535,9 +535,12 @@ static void riscv_deinit_target(struct target *target)
LOG_TARGET_DEBUG(target, "riscv_deinit_target()"); LOG_TARGET_DEBUG(target, "riscv_deinit_target()");
struct riscv_info *info = target->arch_info; struct riscv_info *info = target->arch_info;
struct target_type *tt = get_target_type(target); struct target_type *tt = NULL;
if (info->dtm_version != DTM_DTMCS_VERSION_UNKNOWN) {
tt = get_target_type(target);
if (!tt) if (!tt)
LOG_TARGET_ERROR(target, "Could not identify target type."); LOG_TARGET_ERROR(target, "Could not identify target type.");
}
if (riscv_flush_registers(target) != ERROR_OK) if (riscv_flush_registers(target) != ERROR_OK)
LOG_TARGET_ERROR(target, "Failed to flush registers. Ignoring this error."); LOG_TARGET_ERROR(target, "Failed to flush registers. Ignoring this error.");