Remove unnecessary casts

Change-Id: Ia97283707282ccccdc707c969f59337313b4e291
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1767
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
__archive__
Andreas Fritiofson 2013-09-28 21:43:37 +02:00 committed by Spencer Oliver
parent 704082443d
commit ba2fbe2247
20 changed files with 72 additions and 150 deletions

View File

@ -500,7 +500,7 @@ COMMAND_HANDLER(handle_nand_init_command)
static int nand_list_walker(struct nand_flash_controller *c, void *x) static int nand_list_walker(struct nand_flash_controller *c, void *x)
{ {
struct command_context *cmd_ctx = (struct command_context *)x; struct command_context *cmd_ctx = x;
command_print(cmd_ctx, " %s", c->name); command_print(cmd_ctx, " %s", c->name);
return ERROR_OK; return ERROR_OK;
} }

View File

@ -2731,7 +2731,7 @@ static const struct sam3_reg_list sam3_all_regs[] = {
static struct sam3_bank_private *get_sam3_bank_private(struct flash_bank *bank) static struct sam3_bank_private *get_sam3_bank_private(struct flash_bank *bank)
{ {
return (struct sam3_bank_private *)(bank->driver_priv); return bank->driver_priv;
} }
/** /**

View File

@ -1398,7 +1398,7 @@ static const struct sam4_reg_list sam4_all_regs[] = {
static struct sam4_bank_private *get_sam4_bank_private(struct flash_bank *bank) static struct sam4_bank_private *get_sam4_bank_private(struct flash_bank *bank)
{ {
return (struct sam4_bank_private *)(bank->driver_priv); return bank->driver_priv;
} }
/** /**

View File

@ -2506,9 +2506,9 @@ static void cfi_fixup_0002_unlock_addresses(struct flash_bank *bank, const void
static void cfi_fixup_0002_polling_bits(struct flash_bank *bank, const void *param) static void cfi_fixup_0002_polling_bits(struct flash_bank *bank, const void *param)
{ {
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
const int status_poll_mask = *(const int *)param; const int *status_poll_mask = param;
cfi_info->status_poll_mask = status_poll_mask; cfi_info->status_poll_mask = *status_poll_mask;
} }

View File

@ -578,8 +578,7 @@ static int efm32x_write_block(struct flash_bank *bank, uint8_t *buf,
}; };
ret = target_write_buffer(target, write_algorithm->address, ret = target_write_buffer(target, write_algorithm->address,
sizeof(efm32x_flash_write_code), sizeof(efm32x_flash_write_code), efm32x_flash_write_code);
(uint8_t *)efm32x_flash_write_code);
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;

View File

@ -505,7 +505,7 @@ static int em357_write_block(struct flash_bank *bank, uint8_t *buffer,
; ;
retval = target_write_buffer(target, write_algorithm->address, retval = target_write_buffer(target, write_algorithm->address,
sizeof(em357_flash_write_code), (uint8_t *)em357_flash_write_code); sizeof(em357_flash_write_code), em357_flash_write_code);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;

View File

@ -258,7 +258,7 @@ static int mdr_write_block(struct flash_bank *bank, uint8_t *buffer,
}; };
retval = target_write_buffer(target, write_algorithm->address, retval = target_write_buffer(target, write_algorithm->address,
sizeof(mdr32fx_flash_write_code), (uint8_t *)mdr32fx_flash_write_code); sizeof(mdr32fx_flash_write_code), mdr32fx_flash_write_code);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;

View File

@ -1042,7 +1042,7 @@ static int stellaris_write_block(struct flash_bank *bank,
target_write_buffer(target, write_algorithm->address, target_write_buffer(target, write_algorithm->address,
sizeof(stellaris_write_code), sizeof(stellaris_write_code),
(uint8_t *) stellaris_write_code); stellaris_write_code);
armv7m_info.common_magic = ARMV7M_COMMON_MAGIC; armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
armv7m_info.core_mode = ARM_MODE_THREAD; armv7m_info.core_mode = ARM_MODE_THREAD;

View File

@ -541,7 +541,7 @@ static int stm32x_write_block(struct flash_bank *bank, uint8_t *buffer,
retval = target_write_buffer(target, write_algorithm->address, retval = target_write_buffer(target, write_algorithm->address,
sizeof(stm32x_flash_write_code), sizeof(stm32x_flash_write_code),
(uint8_t *)stm32x_flash_write_code); stm32x_flash_write_code);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;

View File

@ -259,7 +259,7 @@ static int stm32lx_write_half_pages(struct flash_bank *bank, uint8_t *buffer,
retval = target_write_buffer(target, retval = target_write_buffer(target,
write_algorithm->address, write_algorithm->address,
sizeof(stm32lx_flash_write_code), sizeof(stm32lx_flash_write_code),
(uint8_t *)stm32lx_flash_write_code); stm32lx_flash_write_code);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
target_free_working_area(target, write_algorithm); target_free_working_area(target, write_algorithm);
return retval; return retval;

View File

@ -57,7 +57,7 @@ struct log_capture_state {
static void tcl_output(void *privData, const char *file, unsigned line, static void tcl_output(void *privData, const char *file, unsigned line,
const char *function, const char *string) const char *function, const char *string)
{ {
struct log_capture_state *state = (struct log_capture_state *)privData; struct log_capture_state *state = privData;
Jim_AppendString(state->interp, state->output, string, strlen(string)); Jim_AppendString(state->interp, state->output, string, strlen(string));
} }

View File

@ -36,8 +36,7 @@ static char **script_search_dirs;
void add_script_search_dir(const char *dir) void add_script_search_dir(const char *dir)
{ {
num_script_dirs++; num_script_dirs++;
script_search_dirs = script_search_dirs = realloc(script_search_dirs, (num_script_dirs + 1) * sizeof(char *));
(char **)realloc(script_search_dirs, (num_script_dirs + 1) * sizeof(char *));
script_search_dirs[num_script_dirs-1] = strdup(dir); script_search_dirs[num_script_dirs-1] = strdup(dir);
script_search_dirs[num_script_dirs] = NULL; script_search_dirs[num_script_dirs] = NULL;
@ -48,8 +47,7 @@ void add_script_search_dir(const char *dir)
void add_config_command(const char *cfg) void add_config_command(const char *cfg)
{ {
num_config_files++; num_config_files++;
config_file_names = config_file_names = realloc(config_file_names, (num_config_files + 1) * sizeof(char *));
(char **)realloc(config_file_names, (num_config_files + 1) * sizeof(char *));
config_file_names[num_config_files-1] = strdup(cfg); config_file_names[num_config_files-1] = strdup(cfg);
config_file_names[num_config_files] = NULL; config_file_names[num_config_files] = NULL;

View File

@ -116,7 +116,7 @@ void *cmd_queue_alloc(size_t size)
offset = (*p_page)->used; offset = (*p_page)->used;
(*p_page)->used += size; (*p_page)->used += size;
t = (uint8_t *)((*p_page)->address); t = (*p_page)->address;
return t + offset; return t + offset;
} }

View File

@ -26,7 +26,7 @@
static inline void interface_jtag_add_scan_check_alloc(struct scan_field *field) static inline void interface_jtag_add_scan_check_alloc(struct scan_field *field)
{ {
unsigned num_bytes = DIV_ROUND_UP(field->num_bits, 8); unsigned num_bytes = DIV_ROUND_UP(field->num_bits, 8);
field->in_value = (uint8_t *)cmd_queue_alloc(num_bytes); field->in_value = cmd_queue_alloc(num_bytes);
} }
void interface_jtag_add_dr_out(struct jtag_tap *tap, void interface_jtag_add_dr_out(struct jtag_tap *tap,

View File

@ -724,7 +724,7 @@ struct transfer_result {
static LIBUSB_CALL void read_cb(struct libusb_transfer *transfer) static LIBUSB_CALL void read_cb(struct libusb_transfer *transfer)
{ {
struct transfer_result *res = (struct transfer_result *)transfer->user_data; struct transfer_result *res = transfer->user_data;
struct mpsse_ctx *ctx = res->ctx; struct mpsse_ctx *ctx = res->ctx;
unsigned packet_size = ctx->max_packet_size; unsigned packet_size = ctx->max_packet_size;
@ -762,7 +762,7 @@ static LIBUSB_CALL void read_cb(struct libusb_transfer *transfer)
static LIBUSB_CALL void write_cb(struct libusb_transfer *transfer) static LIBUSB_CALL void write_cb(struct libusb_transfer *transfer)
{ {
struct transfer_result *res = (struct transfer_result *)transfer->user_data; struct transfer_result *res = transfer->user_data;
struct mpsse_ctx *ctx = res->ctx; struct mpsse_ctx *ctx = res->ctx;
res->transferred += transfer->actual_length; res->transferred += transfer->actual_length;

View File

@ -350,8 +350,8 @@ static int opendous_init(void)
usb_in_buffer = malloc(opendous_probe->BUFFERSIZE); usb_in_buffer = malloc(opendous_probe->BUFFERSIZE);
usb_out_buffer = malloc(opendous_probe->BUFFERSIZE); usb_out_buffer = malloc(opendous_probe->BUFFERSIZE);
pending_scan_results_buffer = (struct pending_scan_result *) pending_scan_results_buffer = malloc(
malloc(MAX_PENDING_SCAN_RESULTS * sizeof(struct pending_scan_result)); MAX_PENDING_SCAN_RESULTS * sizeof(*pending_scan_results_buffer));
opendous_jtag_handle = opendous_usb_open(); opendous_jtag_handle = opendous_usb_open();
@ -718,7 +718,7 @@ struct opendous_jtag *opendous_usb_open(void)
jtag_libusb_set_configuration(devh, 0); jtag_libusb_set_configuration(devh, 0);
jtag_libusb_claim_interface(devh, 0); jtag_libusb_claim_interface(devh, 0);
result = (struct opendous_jtag *) malloc(sizeof(struct opendous_jtag)); result = malloc(sizeof(*result));
result->usb_handle = devh; result->usb_handle = devh;
return result; return result;
} }

View File

@ -48,7 +48,7 @@ static struct sequence *queue_add_tail(struct queue *queue, int len)
} }
struct sequence *next; struct sequence *next;
next = (struct sequence *)malloc(sizeof(*next)); next = malloc(sizeof(*next));
if (next) { if (next) {
next->tms = calloc(1, DIV_ROUND_UP(len, 8)); next->tms = calloc(1, DIV_ROUND_UP(len, 8));
if (next->tms) { if (next->tms) {
@ -98,7 +98,7 @@ static void queue_free(struct queue *queue)
static struct queue *queue_alloc(void) static struct queue *queue_alloc(void)
{ {
struct queue *queue = (struct queue *)malloc(sizeof(struct queue)); struct queue *queue = malloc(sizeof(*queue));
if (queue) if (queue)
queue->head = NULL; queue->head = NULL;
else else
@ -277,7 +277,7 @@ static int osbdm_swap(struct osbdm *osbdm, void *tms, void *tdi,
/* Copy TDO responce /* Copy TDO responce
*/ */
uint8_t *buffer = (uint8_t *)osbdm->buffer + 4; uint8_t *buffer = osbdm->buffer + 4;
for (int bit_idx = 0; bit_idx < length; ) { for (int bit_idx = 0; bit_idx < length; ) {
int bit_count = length - bit_idx; int bit_count = length - bit_idx;
if (bit_count > 16) if (bit_count > 16)

View File

@ -209,12 +209,10 @@ static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t siz
/** */ /** */
static int stlink_usb_xfer_v1_get_status(void *handle) static int stlink_usb_xfer_v1_get_status(void *handle)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
/* read status */ /* read status */
memset(h->cmdbuf, 0, STLINK_SG_SIZE); memset(h->cmdbuf, 0, STLINK_SG_SIZE);
@ -244,12 +242,10 @@ static int stlink_usb_xfer_v1_get_status(void *handle)
/** */ /** */
static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size) static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (jtag_libusb_bulk_write(h->fd, STLINK_TX_EP, (char *)h->cmdbuf, cmdsize, if (jtag_libusb_bulk_write(h->fd, STLINK_TX_EP, (char *)h->cmdbuf, cmdsize,
STLINK_WRITE_TIMEOUT) != cmdsize) { STLINK_WRITE_TIMEOUT) != cmdsize) {
return ERROR_FAIL; return ERROR_FAIL;
@ -276,12 +272,10 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int
static int stlink_usb_xfer_v1_get_sense(void *handle) static int stlink_usb_xfer_v1_get_sense(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 16); stlink_usb_init_buffer(handle, STLINK_RX_EP, 16);
h->cmdbuf[h->cmdidx++] = REQUEST_SENSE; h->cmdbuf[h->cmdidx++] = REQUEST_SENSE;
@ -305,12 +299,10 @@ static int stlink_usb_xfer_v1_get_sense(void *handle)
static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size) static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size)
{ {
int err, cmdsize = STLINK_CMD_SIZE_V2; int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->version.stlink == 1) if (h->version.stlink == 1)
cmdsize = STLINK_SG_SIZE; cmdsize = STLINK_SG_SIZE;
@ -337,12 +329,10 @@ static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size)
/** */ /** */
static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size) static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
assert(h->version.stlink >= 2); assert(h->version.stlink >= 2);
if (jtag_libusb_bulk_read(h->fd, STLINK_TRACE_EP, (char *)buf, if (jtag_libusb_bulk_read(h->fd, STLINK_TRACE_EP, (char *)buf,
@ -357,9 +347,7 @@ static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size)
/** */ /** */
static void stlink_usb_xfer_v1_create_cmd(void *handle, uint8_t direction, uint32_t size) static void stlink_usb_xfer_v1_create_cmd(void *handle, uint8_t direction, uint32_t size)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
h = (struct stlink_usb_handle_s *)handle;
/* fill the send buffer */ /* fill the send buffer */
strcpy((char *)h->cmdbuf, "USBC"); strcpy((char *)h->cmdbuf, "USBC");
@ -376,9 +364,7 @@ static void stlink_usb_xfer_v1_create_cmd(void *handle, uint8_t direction, uint3
/** */ /** */
static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t size) static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t size)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
h = (struct stlink_usb_handle_s *)handle;
h->direction = direction; h->direction = direction;
@ -400,12 +386,10 @@ static int stlink_usb_error_check(void *handle)
{ {
int res; int res;
const char *err_msg = 0; const char *err_msg = 0;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
/* TODO: no error checking yet on api V1 */ /* TODO: no error checking yet on api V1 */
if (h->jtag_api == STLINK_JTAG_API_V1) if (h->jtag_api == STLINK_JTAG_API_V1)
h->databuf[0] = STLINK_DEBUG_ERR_OK; h->databuf[0] = STLINK_DEBUG_ERR_OK;
@ -432,12 +416,10 @@ static int stlink_usb_version(void *handle)
{ {
int res; int res;
uint16_t v; uint16_t v;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 6); stlink_usb_init_buffer(handle, STLINK_RX_EP, 6);
h->cmdbuf[h->cmdidx++] = STLINK_GET_VERSION; h->cmdbuf[h->cmdidx++] = STLINK_GET_VERSION;
@ -476,11 +458,9 @@ static int stlink_usb_version(void *handle)
static int stlink_usb_check_voltage(void *handle, float *target_voltage) static int stlink_usb_check_voltage(void *handle, float *target_voltage)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
uint32_t adc_results[2]; uint32_t adc_results[2];
h = (struct stlink_usb_handle_s *)handle;
/* only supported by stlink/v2 and for firmware >= 13 */ /* only supported by stlink/v2 and for firmware >= 13 */
if (h->version.stlink == 1 || h->version.jtag < 13) if (h->version.stlink == 1 || h->version.jtag < 13)
return ERROR_COMMAND_NOTFOUND; return ERROR_COMMAND_NOTFOUND;
@ -512,12 +492,10 @@ static int stlink_usb_check_voltage(void *handle, float *target_voltage)
static int stlink_usb_current_mode(void *handle, uint8_t *mode) static int stlink_usb_current_mode(void *handle, uint8_t *mode)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_GET_CURRENT_MODE; h->cmdbuf[h->cmdidx++] = STLINK_GET_CURRENT_MODE;
@ -537,12 +515,10 @@ static int stlink_usb_mode_enter(void *handle, enum stlink_mode type)
{ {
int res; int res;
int rx_size = 0; int rx_size = 0;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
/* on api V2 we are able the read the latest command /* on api V2 we are able the read the latest command
* status * status
* TODO: we need the test on api V1 too * TODO: we need the test on api V1 too
@ -593,12 +569,10 @@ static int stlink_usb_mode_enter(void *handle, enum stlink_mode type)
static int stlink_usb_mode_leave(void *handle, enum stlink_mode type) static int stlink_usb_mode_leave(void *handle, enum stlink_mode type)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_NULL_EP, 0); stlink_usb_init_buffer(handle, STLINK_NULL_EP, 0);
switch (type) { switch (type) {
@ -636,12 +610,10 @@ static int stlink_usb_init_mode(void *handle, bool connect_under_reset)
int res; int res;
uint8_t mode; uint8_t mode;
enum stlink_mode emode; enum stlink_mode emode;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
res = stlink_usb_current_mode(handle, &mode); res = stlink_usb_current_mode(handle, &mode);
if (res != ERROR_OK) if (res != ERROR_OK)
@ -750,12 +722,10 @@ static int stlink_usb_init_mode(void *handle, bool connect_under_reset)
static int stlink_usb_idcode(void *handle, uint32_t *idcode) static int stlink_usb_idcode(void *handle, uint32_t *idcode)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 4); stlink_usb_init_buffer(handle, STLINK_RX_EP, 4);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -775,13 +745,11 @@ static int stlink_usb_idcode(void *handle, uint32_t *idcode)
static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *val) static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *val)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
int res; int res;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 8); stlink_usb_init_buffer(handle, STLINK_RX_EP, 8);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -802,12 +770,10 @@ static int stlink_usb_v2_read_debug_reg(void *handle, uint32_t addr, uint32_t *v
static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -831,12 +797,10 @@ static int stlink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val)
/** */ /** */
static void stlink_usb_trace_read(void *handle) static void stlink_usb_trace_read(void *handle)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->trace.enabled && h->version.jtag >= STLINK_TRACE_MIN_VERSION) { if (h->trace.enabled && h->version.jtag >= STLINK_TRACE_MIN_VERSION) {
int res; int res;
@ -889,12 +853,10 @@ static enum target_state stlink_usb_v2_get_status(void *handle)
static enum target_state stlink_usb_state(void *handle) static enum target_state stlink_usb_state(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->jtag_api == STLINK_JTAG_API_V2) if (h->jtag_api == STLINK_JTAG_API_V2)
return stlink_usb_v2_get_status(handle); return stlink_usb_v2_get_status(handle);
@ -920,12 +882,10 @@ static enum target_state stlink_usb_state(void *handle)
static int stlink_usb_reset(void *handle) static int stlink_usb_reset(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -952,12 +912,10 @@ static int stlink_usb_reset(void *handle)
static int stlink_usb_assert_srst(void *handle, int srst) static int stlink_usb_assert_srst(void *handle, int srst)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->jtag_api == STLINK_JTAG_API_V1) if (h->jtag_api == STLINK_JTAG_API_V1)
return ERROR_COMMAND_NOTFOUND; return ERROR_COMMAND_NOTFOUND;
@ -980,12 +938,10 @@ static int stlink_configure_target_trace_port(void *handle)
{ {
int res; int res;
uint32_t reg; uint32_t reg;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
/* configure the TPI */ /* configure the TPI */
/* enable the trace subsystem */ /* enable the trace subsystem */
@ -1037,12 +993,10 @@ out:
static void stlink_usb_trace_disable(void *handle) static void stlink_usb_trace_disable(void *handle)
{ {
int res = ERROR_OK; int res = ERROR_OK;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
assert(h->version.jtag >= STLINK_TRACE_MIN_VERSION); assert(h->version.jtag >= STLINK_TRACE_MIN_VERSION);
LOG_DEBUG("Tracing: disable\n"); LOG_DEBUG("Tracing: disable\n");
@ -1061,12 +1015,10 @@ static void stlink_usb_trace_disable(void *handle)
static int stlink_usb_trace_enable(void *handle) static int stlink_usb_trace_enable(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->version.jtag >= STLINK_TRACE_MIN_VERSION) { if (h->version.jtag >= STLINK_TRACE_MIN_VERSION) {
uint32_t trace_hz; uint32_t trace_hz;
@ -1105,12 +1057,10 @@ static int stlink_usb_trace_enable(void *handle)
static int stlink_usb_run(void *handle) static int stlink_usb_run(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->jtag_api == STLINK_JTAG_API_V2) { if (h->jtag_api == STLINK_JTAG_API_V2) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN); res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
@ -1142,12 +1092,10 @@ static int stlink_usb_run(void *handle)
static int stlink_usb_halt(void *handle) static int stlink_usb_halt(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->jtag_api == STLINK_JTAG_API_V2) { if (h->jtag_api == STLINK_JTAG_API_V2) {
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN); res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
@ -1174,12 +1122,10 @@ static int stlink_usb_halt(void *handle)
static int stlink_usb_step(void *handle) static int stlink_usb_step(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->jtag_api == STLINK_JTAG_API_V2) { if (h->jtag_api == STLINK_JTAG_API_V2) {
/* TODO: this emulates the v1 api, it should really use a similar auto mask isr /* TODO: this emulates the v1 api, it should really use a similar auto mask isr
* that the cortex-m3 currently does. */ * that the cortex-m3 currently does. */
@ -1205,12 +1151,10 @@ static int stlink_usb_step(void *handle)
static int stlink_usb_read_regs(void *handle) static int stlink_usb_read_regs(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 84); stlink_usb_init_buffer(handle, STLINK_RX_EP, 84);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1231,12 +1175,10 @@ static int stlink_usb_read_regs(void *handle)
static int stlink_usb_read_reg(void *handle, int num, uint32_t *val) static int stlink_usb_read_reg(void *handle, int num, uint32_t *val)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, h->jtag_api == STLINK_JTAG_API_V1 ? 4 : 8); stlink_usb_init_buffer(handle, STLINK_RX_EP, h->jtag_api == STLINK_JTAG_API_V1 ? 4 : 8);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1265,12 +1207,10 @@ static int stlink_usb_read_reg(void *handle, int num, uint32_t *val)
static int stlink_usb_write_reg(void *handle, int num, uint32_t val) static int stlink_usb_write_reg(void *handle, int num, uint32_t val)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2); stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1293,12 +1233,10 @@ static int stlink_usb_write_reg(void *handle, int num, uint32_t val)
static int stlink_usb_get_rw_status(void *handle) static int stlink_usb_get_rw_status(void *handle)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
h = (struct stlink_usb_handle_s *)handle;
if (h->jtag_api == STLINK_JTAG_API_V1) if (h->jtag_api == STLINK_JTAG_API_V1)
return ERROR_OK; return ERROR_OK;
@ -1321,7 +1259,7 @@ static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len,
{ {
int res; int res;
uint16_t read_len = len; uint16_t read_len = len;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
@ -1331,8 +1269,6 @@ static int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len,
return ERROR_FAIL; return ERROR_FAIL;
} }
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, read_len); stlink_usb_init_buffer(handle, STLINK_RX_EP, read_len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1361,7 +1297,7 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len,
const uint8_t *buffer) const uint8_t *buffer)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
@ -1371,8 +1307,6 @@ static int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len,
return ERROR_FAIL; return ERROR_FAIL;
} }
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_TX_EP, len); stlink_usb_init_buffer(handle, STLINK_TX_EP, len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1395,7 +1329,7 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len,
uint8_t *buffer) uint8_t *buffer)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
@ -1405,8 +1339,6 @@ static int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len,
return ERROR_TARGET_UNALIGNED_ACCESS; return ERROR_TARGET_UNALIGNED_ACCESS;
} }
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_RX_EP, len); stlink_usb_init_buffer(handle, STLINK_RX_EP, len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1431,7 +1363,7 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len,
const uint8_t *buffer) const uint8_t *buffer)
{ {
int res; int res;
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = handle;
assert(handle != NULL); assert(handle != NULL);
@ -1441,8 +1373,6 @@ static int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len,
return ERROR_TARGET_UNALIGNED_ACCESS; return ERROR_TARGET_UNALIGNED_ACCESS;
} }
h = (struct stlink_usb_handle_s *)handle;
stlink_usb_init_buffer(handle, STLINK_TX_EP, len); stlink_usb_init_buffer(handle, STLINK_TX_EP, len);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -1473,7 +1403,7 @@ static int stlink_usb_read_mem(void *handle, uint32_t addr, uint32_t size,
{ {
int retval = ERROR_OK; int retval = ERROR_OK;
uint32_t bytes_remaining; uint32_t bytes_remaining;
struct stlink_usb_handle_s *h = (struct stlink_usb_handle_s *)handle; struct stlink_usb_handle_s *h = handle;
/* calculate byte count */ /* calculate byte count */
count *= size; count *= size;
@ -1534,7 +1464,7 @@ static int stlink_usb_write_mem(void *handle, uint32_t addr, uint32_t size,
{ {
int retval = ERROR_OK; int retval = ERROR_OK;
uint32_t bytes_remaining; uint32_t bytes_remaining;
struct stlink_usb_handle_s *h = (struct stlink_usb_handle_s *)handle; struct stlink_usb_handle_s *h = handle;
/* calculate byte count */ /* calculate byte count */
count *= size; count *= size;
@ -1593,9 +1523,7 @@ static int stlink_usb_write_mem(void *handle, uint32_t addr, uint32_t size,
/** */ /** */
static int stlink_usb_close(void *fd) static int stlink_usb_close(void *fd)
{ {
struct stlink_usb_handle_s *h; struct stlink_usb_handle_s *h = fd;
h = (struct stlink_usb_handle_s *)fd;
if (h->fd) if (h->fd)
jtag_libusb_close(h->fd); jtag_libusb_close(h->fd);

View File

@ -241,8 +241,7 @@ RESULT versaloon_init(void)
uint32_t timeout_tmp; uint32_t timeout_tmp;
/* malloc temporary buffer */ /* malloc temporary buffer */
versaloon_buf = versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
if (NULL == versaloon_buf) { if (NULL == versaloon_buf) {
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
@ -274,15 +273,13 @@ RESULT versaloon_init(void)
free(versaloon_buf); free(versaloon_buf);
versaloon_buf = NULL; versaloon_buf = NULL;
versaloon_buf = versaloon_buf = malloc(versaloon_interface.usb_setting.buf_size);
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size);
if (NULL == versaloon_buf) { if (NULL == versaloon_buf) {
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);
return ERRCODE_NOT_ENOUGH_MEMORY; return ERRCODE_NOT_ENOUGH_MEMORY;
} }
versaloon_cmd_buf = versaloon_cmd_buf = malloc(versaloon_interface.usb_setting.buf_size - 3);
(uint8_t *)malloc(versaloon_interface.usb_setting.buf_size - 3);
if (NULL == versaloon_cmd_buf) { if (NULL == versaloon_cmd_buf) {
versaloon_fini(); versaloon_fini();
LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY); LOG_ERROR(ERRMSG_NOT_ENOUGH_MEMORY);

View File

@ -304,9 +304,9 @@ static int vsllink_init(void)
/* malloc buffer size for tap */ /* malloc buffer size for tap */
tap_buffer_size = versaloon_interface.usb_setting.buf_size / 2 - 32; tap_buffer_size = versaloon_interface.usb_setting.buf_size / 2 - 32;
vsllink_free_buffer(); vsllink_free_buffer();
tdi_buffer = (uint8_t *)malloc(tap_buffer_size); tdi_buffer = malloc(tap_buffer_size);
tdo_buffer = (uint8_t *)malloc(tap_buffer_size); tdo_buffer = malloc(tap_buffer_size);
tms_buffer = (uint8_t *)malloc(tap_buffer_size); tms_buffer = malloc(tap_buffer_size);
if ((NULL == tdi_buffer) || (NULL == tdo_buffer) || (NULL == tms_buffer)) { if ((NULL == tdi_buffer) || (NULL == tdo_buffer) || (NULL == tms_buffer)) {
vsllink_quit(); vsllink_quit();
return ERROR_FAIL; return ERROR_FAIL;
@ -660,7 +660,7 @@ static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx,
if (NULL == buff) { if (NULL == buff) {
buf_size = 256; buf_size = 256;
buff = (char *)malloc(buf_size); buff = malloc(buf_size);
if (NULL == buff) { if (NULL == buff) {
ret = 0; ret = 0;
goto free_and_return; goto free_and_return;
@ -669,14 +669,14 @@ static uint8_t usb_check_string(usb_dev_handle *usb, uint8_t stringidx,
} }
strcpy(buff, ""); strcpy(buff, "");
len = usb_get_string_simple(usb, stringidx, (char *)buff, buf_size); len = usb_get_string_simple(usb, stringidx, buff, buf_size);
if ((len < 0) || (len != ((int)strlen((const char *)buff)))) { if ((len < 0) || ((size_t)len != strlen(buff))) {
ret = 0; ret = 0;
goto free_and_return; goto free_and_return;
} }
buff[len] = '\0'; buff[len] = '\0';
if ((string != NULL) && strcmp((const char *)buff, string)) { if ((string != NULL) && strcmp(buff, string)) {
ret = 0; ret = 0;
goto free_and_return; goto free_and_return;
} }