From 4e8cf4aeb555c570633a394be7d2d05f17bb7ba3 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 20 Feb 2017 17:53:18 -0800 Subject: [PATCH] Better error checking in memory access. Change-Id: I985afa433a09f833137f2e244b7eaad2630f6b1a --- src/target/riscv/riscv-013.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index cc06fa722..072d86ac9 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1946,9 +1946,11 @@ static int read_memory(struct target *target, uint32_t address, write_program(target, program); program_delete(program); - execute_abstract_command(target, + if (execute_abstract_command(target, AC_ACCESS_REGISTER_PREEXEC | - abstract_register_size(xlen(target)) | reg_number_to_no(S1)); + abstract_register_size(xlen(target)) | reg_number_to_no(S1)) != ERROR_OK) { + return ERROR_FAIL; + } dmi_write(target, DMI_ABSTRACTCS, DMI_ABSTRACTCS_AUTOEXEC0 | DMI_ABSTRACTCS_CMDERR); for (uint32_t i = 0; i < count; i++) { @@ -2029,9 +2031,11 @@ static int write_memory(struct target *target, uint32_t address, dmi_write(target, DMI_DATA0, value); if (i == 0) { - execute_abstract_command(target, + if (execute_abstract_command(target, AC_ACCESS_REGISTER_WRITE | AC_ACCESS_REGISTER_POSTEXEC | - abstract_register_size(xlen(target)) | reg_number_to_no(S1)); + abstract_register_size(xlen(target)) | reg_number_to_no(S1)) != ERROR_OK) { + return ERROR_FAIL; + } dmi_write(target, DMI_ABSTRACTCS, DMI_ABSTRACTCS_AUTOEXEC0 | DMI_ABSTRACTCS_CMDERR); } else { uint32_t abstractcs;