diff options
author | Andreas Fritiofson <andreas.fritiofson@gmail.com> | 2013-09-30 23:16:20 +0200 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2013-10-31 20:42:34 +0000 |
commit | 517ba0690dcc9e859a05df2113ce32401a5ab254 (patch) | |
tree | 7f437e78a54eb7cb6af06ed589c8ceef0c5277bf /src/target | |
parent | c044c601213ee800cffb21e1f53a89285b3346c9 (diff) | |
download | riscv-openocd-517ba0690dcc9e859a05df2113ce32401a5ab254.zip riscv-openocd-517ba0690dcc9e859a05df2113ce32401a5ab254.tar.gz riscv-openocd-517ba0690dcc9e859a05df2113ce32401a5ab254.tar.bz2 |
Clean up const usage to avoid excessive casting
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 <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1668
Tested-by: jenkins
Reviewed-by: Mathias Küster <kesmtp@freenet.de>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/target')
-rw-r--r-- | src/target/mips32_dmaacc.c | 20 | ||||
-rw-r--r-- | src/target/mips32_dmaacc.h | 2 | ||||
-rw-r--r-- | src/target/mips32_pracc.c | 11 | ||||
-rw-r--r-- | src/target/mips32_pracc.h | 2 | ||||
-rw-r--r-- | src/target/mips_m4k.c | 4 | ||||
-rw-r--r-- | src/target/target.c | 7 | ||||
-rw-r--r-- | src/target/target.h | 6 |
7 files changed, 26 insertions, 26 deletions
diff --git a/src/target/mips32_dmaacc.c b/src/target/mips32_dmaacc.c index eb6cd8c..c2fea21 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 15dd677..45d5b36 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 6a66aa9..da9a2b7 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 4b49855..4dc0bbe 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 23b1767..c2922ce 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 d78f3b1..8ca1cf3 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 44f382a..124dc9b 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); |