From 45f01e0a1269ceb23bfd3a34d2d635bf07463bd0 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Tue, 2 Sep 2014 21:51:51 +0200 Subject: [PATCH] cortex_m: Check return value from cortex_m_dcc_read. Caught by clang. Change-Id: I26d2b845aca431612862ef432b217ca397d9b893 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/2279 Tested-by: jenkins Reviewed-by: Spencer Oliver --- src/target/cortex_m.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index aafc097a0..72dbe9ee6 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1910,7 +1910,9 @@ static int cortex_m_target_request_data(struct target *target, uint32_t i; for (i = 0; i < (size * 4); i++) { - cortex_m_dcc_read(target, &data, &ctrl); + int retval = cortex_m_dcc_read(target, &data, &ctrl); + if (retval != ERROR_OK) + return retval; buffer[i] = data; } @@ -1929,8 +1931,11 @@ static int cortex_m_handle_target_request(void *priv) if (target->state == TARGET_RUNNING) { uint8_t data; uint8_t ctrl; + int retval; - cortex_m_dcc_read(target, &data, &ctrl); + retval = cortex_m_dcc_read(target, &data, &ctrl); + if (retval != ERROR_OK) + return retval; /* check if we have data */ if (ctrl & (1 << 0)) { @@ -1938,12 +1943,12 @@ static int cortex_m_handle_target_request(void *priv) /* we assume target is quick enough */ request = data; - cortex_m_dcc_read(target, &data, &ctrl); - request |= (data << 8); - cortex_m_dcc_read(target, &data, &ctrl); - request |= (data << 16); - cortex_m_dcc_read(target, &data, &ctrl); - request |= (data << 24); + for (int i = 1; i <= 3; i++) { + retval = cortex_m_dcc_read(target, &data, &ctrl); + if (retval != ERROR_OK) + return retval; + request |= ((uint32_t)data << (i * 8)); + } target_request(target, request); } }