From be7702685e5819a6744cdaae283ebe25be9bdec4 Mon Sep 17 00:00:00 2001 From: Tomek CEDRO Date: Sun, 6 Nov 2011 04:22:20 +0000 Subject: transport/swd: Fixed critical bugs in AP/DP read code: 1. double pointer did not return data where is should, 2. calling reads with NULL pointer caused program crash. --- src/transport/swd_core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/transport') diff --git a/src/transport/swd_core.c b/src/transport/swd_core.c index cc9109d6..c18c111a 100644 --- a/src/transport/swd_core.c +++ b/src/transport/swd_core.c @@ -61,12 +61,13 @@ int oocd_swd_queue_idcode_read(struct adiv5_dap *dap, uint8_t *ack, uint32_t *da } int oocd_swd_queue_dp_read(struct adiv5_dap *dap, unsigned reg, uint32_t *data){ - int retval; - retval=swd_dp_read((swd_ctx_t *)dap->ctx, SWD_OPERATION_EXECUTE, reg, (int**) &data); + int retval, *rdata; + retval=swd_dp_read((swd_ctx_t *)dap->ctx, SWD_OPERATION_EXECUTE, reg, &rdata); if (retval<0){ LOG_ERROR("swd_dp_read() error: %s ", swd_error_string(retval)); return ERROR_FAIL; } + if (data!=NULL) *data=(uint32_t)*rdata; return ERROR_OK; } @@ -81,12 +82,13 @@ int oocd_swd_queue_dp_write(struct adiv5_dap *dap, unsigned reg, uint32_t data){ } int oocd_swd_queue_ap_read(struct adiv5_dap *dap, unsigned reg, uint32_t *data){ - int retval; - retval=swd_ap_read((swd_ctx_t *)dap->ctx, SWD_OPERATION_EXECUTE, (char) reg, (int**) &data); + int retval, *rdata; + retval=swd_ap_read((swd_ctx_t *)dap->ctx, SWD_OPERATION_EXECUTE, (char) reg, &rdata); if (retval<0){ LOG_ERROR("swd_ap_read() error: %s ", swd_error_string(retval)); return ERROR_FAIL; } + if (data!=NULL) *data=*rdata; return ERROR_OK; } -- cgit v1.2.3