From 517ba0690dcc9e859a05df2113ce32401a5ab254 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Mon, 30 Sep 2013 23:16:20 +0200 Subject: [PATCH] Clean up const usage to avoid excessive casting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Don't use const on pointers that hold heap allocated data, because that means functions that free them must cast away the const. Do use const on pointer parameters or fields that needn't be modified. Remove pointer casts that are no longer needed after fixing the constness. Change-Id: I5d206f5019982fd1950bc6d6d07b6062dc24e886 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/1668 Tested-by: jenkins Reviewed-by: Mathias Küster Reviewed-by: Spencer Oliver --- src/helper/command.c | 31 ++++++++++++++----------------- src/helper/command.h | 6 +++--- src/helper/fileio.c | 4 ++-- src/jtag/aice/aice_transport.c | 4 ++-- src/jtag/core.c | 10 +++++----- src/jtag/drivers/ulink.c | 10 +++++----- src/jtag/hla/hla_tcl.c | 4 ++-- src/jtag/jtag.h | 6 +++--- src/jtag/tcl.c | 10 +++++----- src/rtos/ChibiOS.c | 2 +- src/rtos/embKernel.c | 2 +- src/rtos/linux.c | 2 +- src/server/gdb_server.c | 8 ++++---- src/server/server.c | 13 ++++++------- src/server/server.h | 13 ++++--------- src/server/tcl_server.c | 2 +- src/server/telnet_server.c | 2 +- src/target/mips32_dmaacc.c | 20 ++++++++++---------- src/target/mips32_dmaacc.h | 2 +- src/target/mips32_pracc.c | 11 ++++++----- src/target/mips32_pracc.h | 2 +- src/target/mips_m4k.c | 4 ++-- src/target/target.c | 7 +++---- src/target/target.h | 6 +++--- 24 files changed, 86 insertions(+), 95 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index a179578c..b374187d 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -146,17 +146,17 @@ void script_debug(Jim_Interp *interp, const char *name, free(dbg); } -static void script_command_args_free(const char **words, unsigned nwords) +static void script_command_args_free(char **words, unsigned nwords) { for (unsigned i = 0; i < nwords; i++) - free((void *)words[i]); + free(words[i]); free(words); } -static const char **script_command_args_alloc( +static char **script_command_args_alloc( unsigned argc, Jim_Obj * const *argv, unsigned *nwords) { - const char **words = malloc(argc * sizeof(char *)); + char **words = malloc(argc * sizeof(char *)); if (NULL == words) return NULL; @@ -198,7 +198,7 @@ static int script_command_run(Jim_Interp *interp, LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ unsigned nwords; - const char **words = script_command_args_alloc(argc, argv, &nwords); + char **words = script_command_args_alloc(argc, argv, &nwords); if (NULL == words) return JIM_ERR; @@ -299,12 +299,9 @@ static void command_free(struct command *c) command_free(tmp); } - if (c->name) - free((void *)c->name); - if (c->help) - free((void *)c->help); - if (c->usage) - free((void *)c->usage); + free(c->name); + free(c->help); + free(c->usage); free(c); } @@ -362,7 +359,7 @@ static int register_command_handler(struct command_context *cmd_ctx, struct command *c) { Jim_Interp *interp = cmd_ctx->interp; - const char *ocd_name = alloc_printf("ocd_%s", c->name); + char *ocd_name = alloc_printf("ocd_%s", c->name); if (NULL == ocd_name) return JIM_ERR; @@ -370,19 +367,19 @@ static int register_command_handler(struct command_context *cmd_ctx, Jim_CmdProc func = c->handler ? &script_command : &command_unknown; int retval = Jim_CreateCommand(interp, ocd_name, func, c, NULL); - free((void *)ocd_name); + free(ocd_name); if (JIM_OK != retval) return retval; /* we now need to add an overrideable proc */ - const char *override_name = alloc_printf( + char *override_name = alloc_printf( "proc %s {args} {eval ocd_bouncer %s $args}", c->name, c->name); if (NULL == override_name) return JIM_ERR; retval = Jim_Eval_Named(interp, override_name, 0, 0); - free((void *)override_name); + free(override_name); return retval; } @@ -1103,7 +1100,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (help_text) { bool replaced = false; if (nc->help) { - free((void *)nc->help); + free(nc->help); replaced = true; } nc->help = strdup(help_text); @@ -1115,7 +1112,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (usage) { bool replaced = false; if (nc->usage) { - free((void *)nc->usage); + free(nc->usage); replaced = true; } nc->usage = strdup(usage); diff --git a/src/helper/command.h b/src/helper/command.h index e969ad96..0f0edbb5 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -162,9 +162,9 @@ struct command_invocation { typedef __COMMAND_HANDLER((*command_handler_t)); struct command { - const char *name; - const char *help; - const char *usage; + char *name; + char *help; + char *usage; struct command *parent; struct command *children; command_handler_t handler; diff --git a/src/helper/fileio.c b/src/helper/fileio.c index 04cfaf59..c6f45e6b 100644 --- a/src/helper/fileio.c +++ b/src/helper/fileio.c @@ -33,7 +33,7 @@ #include "fileio.h" struct fileio_internal { - const char *url; + char *url; ssize_t size; enum fileio_type type; enum fileio_access access; @@ -141,7 +141,7 @@ int fileio_close(struct fileio *fileio_p) retval = fileio_close_local(fileio); - free((void *)fileio->url); + free(fileio->url); fileio->url = NULL; free(fileio); diff --git a/src/jtag/aice/aice_transport.c b/src/jtag/aice/aice_transport.c index 0c208bfa..f3012bb2 100644 --- a/src/jtag/aice/aice_transport.c +++ b/src/jtag/aice/aice_transport.c @@ -109,7 +109,7 @@ static int jim_aice_newtap_cmd(Jim_GetOptInfo *goi) e = Jim_GetOpt_Nvp(goi, opts, &n); if (e != JIM_OK) { Jim_GetOpt_NvpUnknown(goi, opts, 0); - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } @@ -118,7 +118,7 @@ static int jim_aice_newtap_cmd(Jim_GetOptInfo *goi) case NTAP_OPT_EXPECTED_ID: e = jim_newtap_expected_id(n, goi, pTap); if (JIM_OK != e) { - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } diff --git a/src/jtag/core.c b/src/jtag/core.c index b61280cc..08217352 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1326,11 +1326,11 @@ void jtag_tap_free(struct jtag_tap *tap) jtag_unregister_event_callback(&jtag_reset_callback, tap); /** @todo is anything missing? no memory leaks please */ - free((void *)tap->expected); - free((void *)tap->expected_ids); - free((void *)tap->chip); - free((void *)tap->tapname); - free((void *)tap->dotted_name); + free(tap->expected); + free(tap->expected_ids); + free(tap->chip); + free(tap->tapname); + free(tap->dotted_name); free(tap); } diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c index 9a7d8c8e..d93150d6 100644 --- a/src/jtag/drivers/ulink.c +++ b/src/jtag/drivers/ulink.c @@ -169,9 +169,9 @@ int ulink_usb_close(struct ulink **device); /* ULINK MCU (Cypress EZ-USB) specific functions */ int ulink_cpu_reset(struct ulink *device, unsigned char reset_bit); -int ulink_load_firmware_and_renumerate(struct ulink **device, char *filename, +int ulink_load_firmware_and_renumerate(struct ulink **device, const char *filename, uint32_t delay); -int ulink_load_firmware(struct ulink *device, char *filename); +int ulink_load_firmware(struct ulink *device, const char *filename); int ulink_write_firmware_section(struct ulink *device, struct image *firmware_image, int section_index); @@ -362,7 +362,7 @@ int ulink_cpu_reset(struct ulink *device, unsigned char reset_bit) * @return on failure: ERROR_FAIL */ int ulink_load_firmware_and_renumerate(struct ulink **device, - char *filename, uint32_t delay) + const char *filename, uint32_t delay) { int ret; @@ -397,7 +397,7 @@ int ulink_load_firmware_and_renumerate(struct ulink **device, * @return on success: ERROR_OK * @return on failure: ERROR_FAIL */ -int ulink_load_firmware(struct ulink *device, char *filename) +int ulink_load_firmware(struct ulink *device, const char *filename) { struct image ulink_firmware_image; int ret, i; @@ -2284,7 +2284,7 @@ COMMAND_HANDLER(ulink_download_firmware_handler) LOG_INFO("Downloading ULINK firmware image %s", CMD_ARGV[0]); /* Download firmware image in CMD_ARGV[0] */ - ret = ulink_load_firmware_and_renumerate(&ulink_handle, (char *)CMD_ARGV[0], + ret = ulink_load_firmware_and_renumerate(&ulink_handle, CMD_ARGV[0], ULINK_RENUMERATION_DELAY); return ret; diff --git a/src/jtag/hla/hla_tcl.c b/src/jtag/hla/hla_tcl.c index 7bfa6a6d..88cfc590 100644 --- a/src/jtag/hla/hla_tcl.c +++ b/src/jtag/hla/hla_tcl.c @@ -107,7 +107,7 @@ static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi) e = Jim_GetOpt_Nvp(goi, opts, &n); if (e != JIM_OK) { Jim_GetOpt_NvpUnknown(goi, opts, 0); - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } @@ -116,7 +116,7 @@ static int jim_hl_newtap_cmd(Jim_GetOptInfo *goi) case NTAP_OPT_EXPECTED_ID: e = jim_newtap_expected_id(n, goi, pTap); if (JIM_OK != e) { - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index 062563d3..0fe3a4a5 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -121,9 +121,9 @@ struct scan_field { }; struct jtag_tap { - const char *chip; - const char *tapname; - const char *dotted_name; + char *chip; + char *tapname; + char *dotted_name; int abs_chain_position; /** Is this TAP disabled after JTAG reset? */ bool disabled_after_reset; diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index b95bf756..3f63ffc1 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -563,7 +563,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) e = Jim_GetOpt_Nvp(goi, opts, &n); if (e != JIM_OK) { Jim_GetOpt_NvpUnknown(goi, opts, 0); - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } @@ -578,7 +578,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) case NTAP_OPT_EXPECTED_ID: e = jim_newtap_expected_id(n, goi, pTap); if (JIM_OK != e) { - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } @@ -588,7 +588,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) case NTAP_OPT_IRCAPTURE: e = jim_newtap_ir_param(n, goi, pTap); if (JIM_OK != e) { - free((void *)pTap->dotted_name); + free(cp); free(pTap); return e; } @@ -1133,14 +1133,14 @@ COMMAND_HANDLER(handle_irscan_command) } int field_size = tap->ir_length; fields[i].num_bits = field_size; - fields[i].out_value = malloc(DIV_ROUND_UP(field_size, 8)); + uint8_t *v = malloc(DIV_ROUND_UP(field_size, 8)); uint64_t value; retval = parse_u64(CMD_ARGV[i * 2 + 1], &value); if (ERROR_OK != retval) goto error_return; - void *v = (void *)fields[i].out_value; buf_set_u64(v, 0, field_size, value); + fields[i].out_value = v; fields[i].in_value = NULL; } diff --git a/src/rtos/ChibiOS.c b/src/rtos/ChibiOS.c index 47e7fc5d..2148e91d 100644 --- a/src/rtos/ChibiOS.c +++ b/src/rtos/ChibiOS.c @@ -552,6 +552,6 @@ static int ChibiOS_create(struct target *target) return -1; } - target->rtos->rtos_specific_params = (void *) &ChibiOS_params_list[i]; + target->rtos->rtos_specific_params = &ChibiOS_params_list[i]; return 0; } diff --git a/src/rtos/embKernel.c b/src/rtos/embKernel.c index 9a45cf0b..f605deb3 100644 --- a/src/rtos/embKernel.c +++ b/src/rtos/embKernel.c @@ -131,7 +131,7 @@ static int embKernel_create(struct target *target) return -1; } - target->rtos->rtos_specific_params = (void *) &embKernel_params_list[i]; + target->rtos->rtos_specific_params = &embKernel_params_list[i]; return 0; } diff --git a/src/rtos/linux.c b/src/rtos/linux.c index e692ada8..2e97a421 100644 --- a/src/rtos/linux.c +++ b/src/rtos/linux.c @@ -1524,7 +1524,7 @@ static int linux_os_create(struct target *target) os_linux->threads_needs_update = 0; os_linux->threadid_count = 1; os_linux->current_threads = NULL; - target->rtos->rtos_specific_params = (void *)os_linux; + target->rtos->rtos_specific_params = os_linux; ct->core_id = target->coreid; ct->threadid = -1; ct->TS = 0xdeadbeef; diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 660e05ef..c49f87c1 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -104,8 +104,8 @@ static int gdb_breakpoint_override; static enum breakpoint_type gdb_breakpoint_override_type; static int gdb_error(struct connection *connection, int retval); -static const char *gdb_port; -static const char *gdb_port_next; +static char *gdb_port; +static char *gdb_port_next; static void gdb_log_callback(void *priv, const char *file, unsigned line, const char *function, const char *string); @@ -2900,7 +2900,7 @@ static int gdb_target_add_one(struct target *target) portnumber = strtol(gdb_port_next, &end, 0); if (!*end) { if (parse_long(gdb_port_next, &portnumber) == ERROR_OK) { - free((void *)gdb_port_next); + free(gdb_port_next); gdb_port_next = alloc_printf("%d", portnumber+1); } } @@ -2947,7 +2947,7 @@ COMMAND_HANDLER(handle_gdb_port_command) { int retval = CALL_COMMAND_HANDLER(server_pipe_command, &gdb_port); if (ERROR_OK == retval) { - free((void *)gdb_port_next); + free(gdb_port_next); gdb_port_next = strdup(gdb_port); } return retval; diff --git a/src/server/server.c b/src/server/server.c index 01e84412..5e1ae36b 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -303,14 +303,14 @@ static int remove_services(void) struct service *next = c->next; if (c->name) - free((void *)c->name); + free(c->name); if (c->type == CONNECTION_PIPE) { if (c->fd != -1) close(c->fd); } if (c->port) - free((void *)c->port); + free(c->port); if (c->priv) free(c->priv); @@ -612,7 +612,7 @@ int server_register_commands(struct command_context *cmd_ctx) return register_commands(cmd_ctx, NULL, server_command_handlers); } -SERVER_PORT_COMMAND() +COMMAND_HELPER(server_port_command, unsigned short *out) { switch (CMD_ARGC) { case 0: @@ -631,7 +631,7 @@ SERVER_PORT_COMMAND() return ERROR_OK; } -SERVER_PIPE_COMMAND() +COMMAND_HELPER(server_pipe_command, char **out) { switch (CMD_ARGC) { case 0: @@ -643,9 +643,8 @@ SERVER_PIPE_COMMAND() LOG_WARNING("unable to change server port after init"); return ERROR_COMMAND_ARGUMENT_INVALID; } - const char *t = strdup(CMD_ARGV[0]); - free((void *)*out); - *out = t; + free(*out); + *out = strdup(CMD_ARGV[0]); break; } default: diff --git a/src/server/server.h b/src/server/server.h index e6a91953..b4449397 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -55,9 +55,9 @@ typedef int (*input_handler_t)(struct connection *connection); typedef int (*connection_closed_handler_t)(struct connection *connection); struct service { - const char *name; + char *name; enum connection_type type; - const char *port; + char *port; unsigned short portnumber; int fd; struct sockaddr_in sin; @@ -101,14 +101,9 @@ void openocd_sleep_postlude(void); * Call server_port like a normal COMMAND_HANDLER with an extra @a out parameter * to receive the specified port number. */ -#define SERVER_PIPE_COMMAND() \ - COMMAND_HELPER(server_pipe_command, const char **out) -SERVER_PIPE_COMMAND(); +COMMAND_HELPER(server_pipe_command, char **out); -#define SERVER_PORT_COMMAND() \ - COMMAND_HELPER(server_port_command, unsigned short *out) - -SERVER_PORT_COMMAND(); +COMMAND_HELPER(server_port_command, unsigned short *out); #define ERROR_SERVER_REMOTE_CLOSED (-400) #define ERROR_CONNECTION_REJECTED (-401) diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index f3a931ee..91f97786 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -34,7 +34,7 @@ struct tcl_connection { int tc_outerror;/* flag an output error */ }; -static const char *tcl_port; +static char *tcl_port; /* handlers */ static int tcl_new_connection(struct connection *connection); diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index f9517856..92d8c5ea 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -32,7 +32,7 @@ #include #include -static const char *telnet_port; +static char *telnet_port; static char *negotiate = "\xFF\xFB\x03" /* IAC WILL Suppress Go Ahead */ diff --git a/src/target/mips32_dmaacc.c b/src/target/mips32_dmaacc.c index eb6cd8ce..c2fea21d 100644 --- a/src/target/mips32_dmaacc.c +++ b/src/target/mips32_dmaacc.c @@ -38,11 +38,11 @@ static int mips32_dmaacc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint32_t *buf); static int mips32_dmaacc_write_mem8(struct mips_ejtag *ejtag_info, - uint32_t addr, int count, uint8_t *buf); + uint32_t addr, int count, const uint8_t *buf); static int mips32_dmaacc_write_mem16(struct mips_ejtag *ejtag_info, - uint32_t addr, int count, uint16_t *buf); + uint32_t addr, int count, const uint16_t *buf); static int mips32_dmaacc_write_mem32(struct mips_ejtag *ejtag_info, - uint32_t addr, int count, uint32_t *buf); + uint32_t addr, int count, const uint32_t *buf); /* * The following logic shamelessly cloned from HairyDairyMaid's wrt54g_debrick @@ -407,21 +407,21 @@ static int mips32_dmaacc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, return ERROR_OK; } -int mips32_dmaacc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf) +int mips32_dmaacc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf) { switch (size) { case 1: - return mips32_dmaacc_write_mem8(ejtag_info, addr, count, (uint8_t *)buf); + return mips32_dmaacc_write_mem8(ejtag_info, addr, count, buf); case 2: - return mips32_dmaacc_write_mem16(ejtag_info, addr, count, (uint16_t *)buf); + return mips32_dmaacc_write_mem16(ejtag_info, addr, count, buf); case 4: - return mips32_dmaacc_write_mem32(ejtag_info, addr, count, (uint32_t *)buf); + return mips32_dmaacc_write_mem32(ejtag_info, addr, count, buf); } return ERROR_OK; } -static int mips32_dmaacc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint32_t *buf) +static int mips32_dmaacc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int count, const uint32_t *buf) { int i; int retval; @@ -435,7 +435,7 @@ static int mips32_dmaacc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t add return ERROR_OK; } -static int mips32_dmaacc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint16_t *buf) +static int mips32_dmaacc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int count, const uint16_t *buf) { int i; int retval; @@ -449,7 +449,7 @@ static int mips32_dmaacc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t add return ERROR_OK; } -static int mips32_dmaacc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint8_t *buf) +static int mips32_dmaacc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int count, const uint8_t *buf) { int i; int retval; diff --git a/src/target/mips32_dmaacc.h b/src/target/mips32_dmaacc.h index 15dd677b..45d5b361 100644 --- a/src/target/mips32_dmaacc.h +++ b/src/target/mips32_dmaacc.h @@ -38,6 +38,6 @@ int mips32_dmaacc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf); int mips32_dmaacc_write_mem(struct mips_ejtag *ejtag_info, - uint32_t addr, int size, int count, void *buf); + uint32_t addr, int size, int count, const void *buf); #endif diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index 6a66aa9a..da9a2b71 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -730,16 +730,17 @@ static int mips32_pracc_clean_invalidate_cache(struct mips_ejtag *ejtag_info, return retval; } -static int mips32_pracc_write_mem_generic(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf) +static int mips32_pracc_write_mem_generic(struct mips_ejtag *ejtag_info, + uint32_t addr, int size, int count, const void *buf) { struct pracc_queue_info ctx = {.max_code = 128 * 3 + 6 + 1}; /* alloc memory for the worst case */ pracc_queue_init(&ctx); if (ctx.retval != ERROR_OK) goto exit; - uint32_t *buf32 = buf; - uint16_t *buf16 = buf; - uint8_t *buf8 = buf; + const uint32_t *buf32 = buf; + const uint16_t *buf16 = buf; + const uint8_t *buf8 = buf; while (count) { ctx.code_count = 0; @@ -798,7 +799,7 @@ exit: return ctx.retval; } -int mips32_pracc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf) +int mips32_pracc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf) { int retval = mips32_pracc_write_mem_generic(ejtag_info, addr, size, count, buf); if (retval != ERROR_OK) diff --git a/src/target/mips32_pracc.h b/src/target/mips32_pracc.h index 4b498559..4dc0bbe0 100644 --- a/src/target/mips32_pracc.h +++ b/src/target/mips32_pracc.h @@ -67,7 +67,7 @@ int mips32_pracc_queue_exec(struct mips_ejtag *ejtag_info, int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf); int mips32_pracc_write_mem(struct mips_ejtag *ejtag_info, - uint32_t addr, int size, int count, void *buf); + uint32_t addr, int size, int count, const void *buf); int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_area *source, int write_t, uint32_t addr, int count, uint32_t *buf); diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 23b1767c..c2922ce9 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -1048,9 +1048,9 @@ static int mips_m4k_write_memory(struct target *target, uint32_t address, /* if noDMA off, use DMAACC mode for memory write */ int retval; if (ejtag_info->impcode & EJTAG_IMP_NODMA) - retval = mips32_pracc_write_mem(ejtag_info, address, size, count, (void *)buffer); + retval = mips32_pracc_write_mem(ejtag_info, address, size, count, buffer); else - retval = mips32_dmaacc_write_mem(ejtag_info, address, size, count, (void *)buffer); + retval = mips32_dmaacc_write_mem(ejtag_info, address, size, count, buffer); if (t != NULL) free(t); diff --git a/src/target/target.c b/src/target/target.c index d78f3b16..8ca1cf34 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -377,7 +377,7 @@ void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, u } /* write a uint32_t array to a buffer in target memory endianness */ -void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, uint32_t *srcbuf) +void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf) { uint32_t i; for (i = 0; i < count; i++) @@ -385,7 +385,7 @@ void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_ } /* write a uint16_t array to a buffer in target memory endianness */ -void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, uint16_t *srcbuf) +void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf) { uint32_t i; for (i = 0; i < count; i++) @@ -4260,11 +4260,10 @@ no_params: n->name); return JIM_ERR; } - if (target->variant) - free((void *)(target->variant)); e = Jim_GetOpt_String(goi, &cp, NULL); if (e != JIM_OK) return e; + free(target->variant); target->variant = strdup(cp); } else { if (goi->argc != 0) diff --git a/src/target/target.h b/src/target/target.h index 44f382a2..124dc9b7 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -129,7 +129,7 @@ struct target { int target_number; /* DO NOT USE! field to be removed in 2010 */ struct jtag_tap *tap; /* where on the jtag chain is this */ int32_t coreid; /* which device on the TAP? */ - const char *variant; /* what variant of this chip is it? */ + char *variant; /* what variant of this chip is it? */ /** * Indicates whether this target has been examined. @@ -602,8 +602,8 @@ void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t valu void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf); void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf); -void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, uint32_t *srcbuf); -void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, uint16_t *srcbuf); +void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf); +void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf); int target_read_u32(struct target *target, uint32_t address, uint32_t *value); int target_read_u16(struct target *target, uint32_t address, uint16_t *value); -- 2.39.5