From: OpenOCD-Gerrit <ope...@us...> - 2020-09-05 16:12:45
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 4e98d44fd1dc67f763f06eeecc0453d65b1290dc (commit) via 62329444abc89ad3b37fbb4ebc2edfd1dee23351 (commit) via 47d29ebe11babdddd107ba5edab7e5cd85ce1fee (commit) from aa628304e2a5a629ffee136089c0abee48db355b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4e98d44fd1dc67f763f06eeecc0453d65b1290dc Author: Antonio Borneo <bor...@gm...> Date: Sun Aug 16 21:35:10 2020 +0200 openocd: avoid checking for non NULL pointer to free it The function free() can be called with a NULL pointer as argument, no need to check the argument before. If the pointer is NULL, no operation is performed by free(). Remove the occurrences of pattern: if (ptr) free(ptr); While there replace a sequence malloc(size)+memset(,0,size) with a calloc(1,size). Replace a pointer assignment to '0' with an assignment to NULL. In server/*, an error is logged if the ptr was already NULL. This cannot happen since the pointer was already referenced few lines before and openocd would have been already SIGSEGV in that case, so remove the log. Change-Id: I10822029fe8390b59edff4070575bf7f754e44ac Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5808 Reviewed-by: Adrian M Negreanu <adr...@nx...> Tested-by: jenkins diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index c103ce173..ffdeca898 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -230,8 +230,7 @@ COMMAND_HANDLER(handle_cp_command) else command_print(CMD, "copy failed"); - if (data != NULL) - free(data); + free(data); if (f != NULL) fclose(f); diff --git a/src/rtos/chibios.c b/src/rtos/chibios.c index 4d2b1b2d7..a56d3ce05 100644 --- a/src/rtos/chibios.c +++ b/src/rtos/chibios.c @@ -150,10 +150,8 @@ static int chibios_update_memory_signature(struct rtos *rtos) param = (struct chibios_params *) rtos->rtos_specific_params; /* Free existing memory description.*/ - if (param->signature) { - free(param->signature); - param->signature = 0; - } + free(param->signature); + param->signature = NULL; signature = malloc(sizeof(*signature)); if (!signature) { diff --git a/src/rtos/linux.c b/src/rtos/linux.c index cd1ed218a..dbbf97b44 100644 --- a/src/rtos/linux.c +++ b/src/rtos/linux.c @@ -627,8 +627,7 @@ struct threads *liste_del_task(struct threads *task_list, struct threads **t, task_list = (*t)->next; /* free content of threads */ - if ((*t)->context) - free((*t)->context); + free((*t)->context); free(*t); *t = prev ? prev : task_list; @@ -781,8 +780,7 @@ static int clean_threadlist(struct target *target) while (temp != NULL) { old = temp; - if (temp->context) - free(temp->context); + free(temp->context); temp = temp->next; free(old); @@ -931,10 +929,8 @@ static int linux_task_update(struct target *target, int context) while (thread_list != NULL) { thread_list->status = 0; /*setting all tasks to dead state*/ - if (thread_list->context) { - free(thread_list->context); - thread_list->context = NULL; - } + free(thread_list->context); + thread_list->context = NULL; thread_list = thread_list->next; } diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 97ce255b9..62b65aae1 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -100,9 +100,7 @@ static void os_free(struct target *target) if (!target->rtos) return; - if (target->rtos->symbols) - free(target->rtos->symbols); - + free(target->rtos->symbols); free(target->rtos); target->rtos = NULL; } @@ -646,10 +644,9 @@ int rtos_try_next(struct target *target) return 0; os->type = *type; - if (os->symbols) { - free(os->symbols); - os->symbols = NULL; - } + + free(os->symbols); + os->symbols = NULL; return 1; } diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index f94b72817..85d3c14b1 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -1067,11 +1067,8 @@ static int gdb_connection_closed(struct connection *connection) /* if this connection registered a debug-message receiver delete it */ delete_debug_msg_receiver(connection->cmd_ctx, target); - if (connection->priv) { - free(connection->priv); - connection->priv = NULL; - } else - LOG_ERROR("BUG: connection->priv == NULL"); + free(connection->priv); + connection->priv = NULL; target_unregister_event_callback(gdb_target_callback_event_handler, connection); @@ -1758,8 +1755,7 @@ static __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6))) void xml_printf( char *t = *xml; *xml = realloc(*xml, *size); if (*xml == NULL) { - if (t) - free(t); + free(t); *retval = ERROR_SERVER_REMOTE_CLOSED; return; } diff --git a/src/server/server.c b/src/server/server.c index d96f0b6cf..3b55d0d7c 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -403,19 +403,14 @@ static int remove_services(void) remove_connections(c); - if (c->name) - free(c->name); + free(c->name); if (c->type == CONNECTION_PIPE) { if (c->fd != -1) close(c->fd); } - if (c->port) - free(c->port); - - if (c->priv) - free(c->priv); - + free(c->port); + free(c->priv); /* delete service */ free(c); diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index d0583a9b3..0243c6328 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -451,8 +451,7 @@ static int telnet_input(struct connection *connection) if (*t_con->line && (prev_line == NULL || strcmp(t_con->line, prev_line))) { /* if the history slot is already taken, free it */ - if (t_con->history[t_con->next_history]) - free(t_con->history[t_con->next_history]); + free(t_con->history[t_con->next_history]); /* add line to history */ t_con->history[t_con->next_history] = strdup(t_con->line); @@ -465,8 +464,7 @@ static int telnet_input(struct connection *connection) t_con->current_history = t_con->next_history; - if (t_con->history[t_con->current_history]) - free(t_con->history[t_con->current_history]); + free(t_con->history[t_con->current_history]); t_con->history[t_con->current_history] = strdup(""); } @@ -647,29 +645,22 @@ static int telnet_connection_closed(struct connection *connection) log_remove_callback(telnet_log_callback, connection); - if (t_con->prompt) { - free(t_con->prompt); - t_con->prompt = NULL; - } + free(t_con->prompt); + t_con->prompt = NULL; /* save telnet history */ telnet_save_history(t_con); for (i = 0; i < TELNET_LINE_HISTORY_SIZE; i++) { - if (t_con->history[i]) { - free(t_con->history[i]); - t_con->history[i] = NULL; - } + free(t_con->history[i]); + t_con->history[i] = NULL; } /* if this connection registered a debug-message receiver delete it */ delete_debug_msg_receiver(connection->cmd_ctx, NULL); - if (connection->priv) { - free(connection->priv); - connection->priv = NULL; - } else - LOG_ERROR("BUG: connection->priv == NULL"); + free(connection->priv); + connection->priv = NULL; return ERROR_OK; } diff --git a/src/svf/svf.c b/src/svf/svf.c index 010592076..b62cdae08 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -302,22 +302,17 @@ static int svf_realloc_buffers(size_t len) static void svf_free_xxd_para(struct svf_xxr_para *para) { if (NULL != para) { - if (para->tdi != NULL) { - free(para->tdi); - para->tdi = NULL; - } - if (para->tdo != NULL) { - free(para->tdo); - para->tdo = NULL; - } - if (para->mask != NULL) { - free(para->mask); - para->mask = NULL; - } - if (para->smask != NULL) { - free(para->smask); - para->smask = NULL; - } + free(para->tdi); + para->tdi = NULL; + + free(para->tdo); + para->tdo = NULL; + + free(para->mask); + para->mask = NULL; + + free(para->smask); + para->smask = NULL; } } @@ -546,28 +541,23 @@ free_all: svf_fd = 0; /* free buffers */ - if (svf_command_buffer) { - free(svf_command_buffer); - svf_command_buffer = NULL; - svf_command_buffer_size = 0; - } - if (svf_check_tdo_para) { - free(svf_check_tdo_para); - svf_check_tdo_para = NULL; - svf_check_tdo_para_index = 0; - } - if (svf_tdi_buffer) { - free(svf_tdi_buffer); - svf_tdi_buffer = NULL; - } - if (svf_tdo_buffer) { - free(svf_tdo_buffer); - svf_tdo_buffer = NULL; - } - if (svf_mask_buffer) { - free(svf_mask_buffer); - svf_mask_buffer = NULL; - } + free(svf_command_buffer); + svf_command_buffer = NULL; + svf_command_buffer_size = 0; + + free(svf_check_tdo_para); + svf_check_tdo_para = NULL; + svf_check_tdo_para_index = 0; + + free(svf_tdi_buffer); + svf_tdi_buffer = NULL; + + free(svf_tdo_buffer); + svf_tdo_buffer = NULL; + + free(svf_mask_buffer); + svf_mask_buffer = NULL; + svf_buffer_index = 0; svf_buffer_size = 0; @@ -771,16 +761,12 @@ static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_ int new_byte_len = (new_bit_len + 7) >> 3; if ((NULL == *arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) { - if (*arr != NULL) { - free(*arr); - *arr = NULL; - } - *arr = malloc(new_byte_len); + free(*arr); + *arr = calloc(1, new_byte_len); if (NULL == *arr) { LOG_ERROR("not enough memory"); return ERROR_FAIL; } - memset(*arr, 0, new_byte_len); } return ERROR_OK; } diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c index 53779bb1c..eaa5a3aae 100644 --- a/src/xsvf/xsvf.c +++ b/src/xsvf/xsvf.c @@ -411,12 +411,9 @@ COMMAND_HANDLER(handle_xsvf_command) xsdrsize = be_to_h_u32(xsdrsize_buf); LOG_DEBUG("XSDRSIZE %d", xsdrsize); - if (dr_out_buf) - free(dr_out_buf); - if (dr_in_buf) - free(dr_in_buf); - if (dr_in_mask) - free(dr_in_mask); + free(dr_out_buf); + free(dr_in_buf); + free(dr_in_mask); dr_out_buf = malloc((xsdrsize + 7) / 8); dr_in_buf = malloc((xsdrsize + 7) / 8); @@ -1027,14 +1024,9 @@ COMMAND_HANDLER(handle_xsvf_command) return ERROR_FAIL; } - if (dr_out_buf) - free(dr_out_buf); - - if (dr_in_buf) - free(dr_in_buf); - - if (dr_in_mask) - free(dr_in_mask); + free(dr_out_buf); + free(dr_in_buf); + free(dr_in_mask); close(xsvf_fd); commit 62329444abc89ad3b37fbb4ebc2edfd1dee23351 Author: Antonio Borneo <bor...@gm...> Date: Mon Aug 17 10:08:35 2020 +0200 flash: avoid checking for non NULL pointer to free it The function free() can be called with a NULL pointer as argument, no need to check the argument before. If the pointer is NULL, no operation is performed by free(). Remove the occurrences of pattern: if (ptr) free(ptr); There are cases where the pointer is set to NULL after free(), but then re-assigned within few lines. Drop the setting to NULL when this is evident. Anyway, the compiler will remove the useless assignment so no reason to be too much aggressive in this change. Change-Id: I55b2ce7cbe201410016398933e34d33a4b66e30b Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5811 Tested-by: jenkins diff --git a/src/flash/nand/fileio.c b/src/flash/nand/fileio.c index 1279e45a4..fee401292 100644 --- a/src/flash/nand/fileio.c +++ b/src/flash/nand/fileio.c @@ -99,14 +99,11 @@ int nand_fileio_cleanup(struct nand_fileio_state *state) if (state->file_opened) fileio_close(state->fileio); - if (state->oob) { - free(state->oob); - state->oob = NULL; - } - if (state->page) { - free(state->page); - state->page = NULL; - } + free(state->oob); + state->oob = NULL; + + free(state->page); + state->page = NULL; return ERROR_OK; } int nand_fileio_finish(struct nand_fileio_state *state) diff --git a/src/flash/nor/ambiqmicro.c b/src/flash/nor/ambiqmicro.c index 622943d28..28dc42d82 100644 --- a/src/flash/nor/ambiqmicro.c +++ b/src/flash/nor/ambiqmicro.c @@ -672,10 +672,7 @@ static int ambiqmicro_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages; diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index 1e2a074aa..c9baffc70 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -3530,8 +3530,7 @@ static int sam3_write(struct flash_bank *bank, LOG_DEBUG("Done!"); r = ERROR_OK; done: - if (pagebuffer) - free(pagebuffer); + free(pagebuffer); return r; } diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index 4be3a5962..3f9ea9bfa 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -3009,8 +3009,7 @@ static int sam4_write(struct flash_bank *bank, LOG_DEBUG("Done!"); r = ERROR_OK; done: - if (pagebuffer) - free(pagebuffer); + free(pagebuffer); return r; } diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index 63710d3e0..5fbf8bcaa 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -915,9 +915,7 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer, } free_pb: - if (pb) - free(pb); - + free(pb); return res; } diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index 82306830a..5d6010a2a 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -731,9 +731,7 @@ static int same5_write(struct flash_bank *bank, const uint8_t *buffer, } free_pb: - if (pb) - free(pb); - + free(pb); return res; } diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 4ec1161af..70d4d341b 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -333,10 +333,7 @@ static int avrf_probe(struct flash_bank *bank) } if (avr_info != NULL) { - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* chip found */ bank->base = 0x00000000; diff --git a/src/flash/nor/cc3220sf.c b/src/flash/nor/cc3220sf.c index 5e88aa61b..5427bd3a9 100644 --- a/src/flash/nor/cc3220sf.c +++ b/src/flash/nor/cc3220sf.c @@ -438,10 +438,7 @@ static int cc3220sf_probe(struct flash_bank *bank) size = FLASH_NUM_SECTORS * FLASH_SECTOR_SIZE; num_sectors = FLASH_NUM_SECTORS; - if (NULL != bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); if (NULL == bank->sectors) diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index 887821b79..964e06ac7 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -423,8 +423,7 @@ static int cfi_read_intel_pri_ext(struct flash_bank *bank) struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_intel_pri_ext *pri_ext; - if (cfi_info->pri_ext) - free(cfi_info->pri_ext); + free(cfi_info->pri_ext); pri_ext = malloc(sizeof(struct cfi_intel_pri_ext)); if (pri_ext == NULL) { @@ -520,8 +519,7 @@ static int cfi_read_spansion_pri_ext(struct flash_bank *bank) struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_spansion_pri_ext *pri_ext; - if (cfi_info->pri_ext) - free(cfi_info->pri_ext); + free(cfi_info->pri_ext); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); if (pri_ext == NULL) { @@ -623,8 +621,7 @@ static int cfi_read_atmel_pri_ext(struct flash_bank *bank) struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_spansion_pri_ext *pri_ext; - if (cfi_info->pri_ext) - free(cfi_info->pri_ext); + free(cfi_info->pri_ext); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); if (pri_ext == NULL) { @@ -2593,14 +2590,12 @@ int cfi_probe(struct flash_bank *bank) cfi_info->probed = false; cfi_info->num_erase_regions = 0; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } - if (cfi_info->erase_region_info) { - free(cfi_info->erase_region_info); - cfi_info->erase_region_info = NULL; - } + + free(bank->sectors); + bank->sectors = NULL; + + free(cfi_info->erase_region_info); + cfi_info->erase_region_info = NULL; /* JEDEC standard JESD21C uses 0x5555 and 0x2aaa as unlock addresses, * while CFI compatible AMD/Spansion flashes use 0x555 and 0x2aa diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c index 2c323b07e..6f2900762 100644 --- a/src/flash/nor/efm32.c +++ b/src/flash/nor/efm32.c @@ -951,9 +951,7 @@ reset_pg_and_lock: retval = retval2; cleanup: - if (new_buffer) - free(new_buffer); - + free(new_buffer); return retval; } @@ -987,10 +985,8 @@ static int efm32x_probe(struct flash_bank *bank) assert(num_pages > 0); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; bank->base = base_address; bank->size = (num_pages * efm32_mcu_info.page_size); diff --git a/src/flash/nor/em357.c b/src/flash/nor/em357.c index cb4456209..4e2a169c6 100644 --- a/src/flash/nor/em357.c +++ b/src/flash/nor/em357.c @@ -724,10 +724,7 @@ static int em357_probe(struct flash_bank *bank) LOG_INFO("flash size = %dkbytes", num_pages*page_size/1024); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->base = base_address; bank->size = (num_pages * page_size); diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 43b90f1f0..6b6121d3b 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -2736,14 +2736,11 @@ static int kinetis_probe(struct flash_bank *bank) " please report to OpenOCD mailing list", fcfg2_maxaddr1); } - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } - if (bank->prot_blocks) { - free(bank->prot_blocks); - bank->prot_blocks = NULL; - } + free(bank->sectors); + bank->sectors = NULL; + + free(bank->prot_blocks); + bank->prot_blocks = NULL; if (k_bank->sector_size == 0) { LOG_ERROR("Unknown sector size for bank %u", bank->bank_number); diff --git a/src/flash/nor/kinetis_ke.c b/src/flash/nor/kinetis_ke.c index 6afb3b9e6..349b2564d 100644 --- a/src/flash/nor/kinetis_ke.c +++ b/src/flash/nor/kinetis_ke.c @@ -1145,10 +1145,7 @@ static int kinetis_ke_probe(struct flash_bank *bank) break; } - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); assert(bank->num_sectors > 0); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index c840bd795..bf54f63ba 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -651,10 +651,7 @@ static int max32xxx_probe(struct flash_bank *bank) uint32_t arm_id[2]; uint16_t arm_pid; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = info->flash_size; diff --git a/src/flash/nor/mdr.c b/src/flash/nor/mdr.c index b835f9237..2518c229b 100644 --- a/src/flash/nor/mdr.c +++ b/src/flash/nor/mdr.c @@ -458,8 +458,7 @@ reset_pg_and_lock: retval = retval2; free_buffer: - if (new_buffer) - free(new_buffer); + free(new_buffer); /* read some bytes bytes to flush buffer in flash accelerator. * See errata for 1986VE1T and 1986VE3. Error 0007 */ @@ -573,10 +572,7 @@ static int mdr_probe(struct flash_bank *bank) page_count = mdr_info->page_count; page_size = bank->size / page_count; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->num_sectors = page_count; bank->sectors = malloc(sizeof(struct flash_sector) * page_count); diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c index 0c925bdd3..d2417bc89 100644 --- a/src/flash/nor/msp432.c +++ b/src/flash/nor/msp432.c @@ -902,10 +902,8 @@ static int msp432_probe(struct flash_bank *bank) } } - if (NULL != bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; if (num_sectors > 0) { bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); @@ -1046,7 +1044,7 @@ static void msp432_flash_free_driver_priv(struct flash_bank *bank) /* A single private struct is shared between main and info banks */ /* Only free it on the call for main bank */ - if (is_main && (NULL != bank->driver_priv)) + if (is_main) free(bank->driver_priv); /* Forget about the private struct on both main and info banks */ diff --git a/src/flash/nor/niietcm4.c b/src/flash/nor/niietcm4.c index 2377e14f7..2a20edcee 100644 --- a/src/flash/nor/niietcm4.c +++ b/src/flash/nor/niietcm4.c @@ -1469,9 +1469,7 @@ static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer, } free_buffer: - if (new_buffer) - free(new_buffer); - + free(new_buffer); return retval; } @@ -1681,10 +1679,9 @@ static int niietcm4_probe(struct flash_bank *bank) struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv; struct target *target = bank->target; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; + uint32_t retval; uint32_t chipid; diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c index 9b9185344..ae5ebb932 100644 --- a/src/flash/nor/pic32mx.c +++ b/src/flash/nor/pic32mx.c @@ -591,8 +591,7 @@ static int pic32mx_write_block(struct flash_bank *bank, const uint8_t *buffer, destroy_reg_param(®_params[1]); destroy_reg_param(®_params[2]); - if (new_buffer != NULL) - free(new_buffer); + free(new_buffer); return retval; } @@ -774,10 +773,7 @@ static int pic32mx_probe(struct flash_bank *bank) LOG_INFO("flash size = %" PRId32 "kbytes", num_pages / 1024); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* calculate numbers of pages */ num_pages /= page_size; diff --git a/src/flash/nor/psoc4.c b/src/flash/nor/psoc4.c index 0c656349f..9c2fdf775 100644 --- a/src/flash/nor/psoc4.c +++ b/src/flash/nor/psoc4.c @@ -610,8 +610,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, unsigned int first, break; } - if (sysrq_buffer) - free(sysrq_buffer); + free(sysrq_buffer); psoc4_protect_check(bank); return retval; @@ -714,9 +713,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer, cleanup: jtag_poll_set_enabled(save_poll); - if (sysrq_buffer) - free(sysrq_buffer); - + free(sysrq_buffer); return retval; } @@ -827,9 +824,7 @@ static int psoc4_probe(struct flash_bank *bank) } } - if (bank->sectors) { - free(bank->sectors); - } + free(bank->sectors); psoc4_info->family_id = family_id; psoc4_info->num_macros = num_macros; diff --git a/src/flash/nor/psoc6.c b/src/flash/nor/psoc6.c index c7141738d..09a1bed56 100644 --- a/src/flash/nor/psoc6.c +++ b/src/flash/nor/psoc6.c @@ -585,10 +585,8 @@ static int psoc6_probe(struct flash_bank *bank) /* Calculate size of Main Flash*/ uint32_t flash_sz_bytes = bank_cnt * row_cnt * row_sz; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; size_t bank_size = 0; diff --git a/src/flash/nor/sim3x.c b/src/flash/nor/sim3x.c index 21449041c..76280f1ab 100644 --- a/src/flash/nor/sim3x.c +++ b/src/flash/nor/sim3x.c @@ -801,10 +801,7 @@ static int sim3x_probe(struct flash_bank *bank) if (ret != ERROR_OK) return ret; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->base = FLASH_BASE_ADDRESS; bank->size = sim3x_info->flash_size_kb * SIM3X_FLASH_PAGE_SIZE; diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index 34c9c28fe..55b99de3f 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -1250,10 +1250,7 @@ static int stellaris_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); /* provide this for the benefit of the NOR flash framework */ bank->size = stellaris_info->num_pages * stellaris_info->pagesize; diff --git a/src/flash/nor/stm32f1x.c b/src/flash/nor/stm32f1x.c index a07bd847b..78efc8b47 100644 --- a/src/flash/nor/stm32f1x.c +++ b/src/flash/nor/stm32f1x.c @@ -617,9 +617,7 @@ reset_pg_and_lock: retval = retval2; cleanup: - if (new_buffer) - free(new_buffer); - + free(new_buffer); return retval; } @@ -872,15 +870,11 @@ static int stm32x_probe(struct flash_bank *bank) /* check that calculation result makes sense */ assert(num_pages > 0); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; - if (bank->prot_blocks) { - free(bank->prot_blocks); - bank->prot_blocks = NULL; - } + free(bank->prot_blocks); + bank->prot_blocks = NULL; bank->base = base_address; bank->size = (num_pages * page_size); diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c index 52bad4b0d..e3625f322 100644 --- a/src/flash/nor/stm32f2x.c +++ b/src/flash/nor/stm32f2x.c @@ -1013,17 +1013,13 @@ static int stm32x_probe(struct flash_bank *bank) stm32x_info->protection_bits = 12; /* max. number of nWRPi bits (in FLASH_OPTCR !!!) */ num_prot_blocks = 0; - if (bank->sectors) { - free(bank->sectors); - bank->num_sectors = 0; - bank->sectors = NULL; - } + free(bank->sectors); + bank->num_sectors = 0; + bank->sectors = NULL; - if (bank->prot_blocks) { - free(bank->prot_blocks); - bank->num_prot_blocks = 0; - bank->prot_blocks = NULL; - } + free(bank->prot_blocks); + bank->num_prot_blocks = 0; + bank->prot_blocks = NULL; /* if explicitly called out as OTP bank, short circuit probe */ if (stm32x_is_otp(bank)) { diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index 9f456b29d..ac7d75948 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -853,8 +853,7 @@ static int stm32x_probe(struct flash_bank *bank) bank->num_sectors = flash_size_in_kb / stm32x_info->part_info->page_size_kb; assert(bank->num_sectors > 0); - if (bank->sectors) - free(bank->sectors); + free(bank->sectors); bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024, bank->num_sectors); @@ -871,8 +870,7 @@ static int stm32x_probe(struct flash_bank *bank) bank->num_prot_blocks = bank->num_sectors / wpsn; assert(bank->num_prot_blocks > 0); - if (bank->prot_blocks) - free(bank->prot_blocks); + free(bank->prot_blocks); bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024, bank->num_prot_blocks); diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index c56bd6d60..0b5e1b04b 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -1040,10 +1040,7 @@ static int stm32l4_probe(struct flash_bank *bank) assert((stm32l4_info->wrpxxr_mask & 0xFFFF0000) == 0); LOG_DEBUG("WRPxxR mask 0x%04" PRIx16, (uint16_t)stm32l4_info->wrpxxr_mask); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->size = (flash_size_kb + gap_size_kb) * 1024; bank->base = STM32_FLASH_BANK_BASE; diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index cf5b36040..34c7408b0 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -836,10 +836,7 @@ static int stm32lx_probe(struct flash_bank *bank) /* calculate numbers of sectors (4kB per sector) */ unsigned int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->size = flash_size_in_kb * 1024; bank->base = base_address; diff --git a/src/flash/nor/swm050.c b/src/flash/nor/swm050.c index 020a1dac7..98361eb91 100644 --- a/src/flash/nor/swm050.c +++ b/src/flash/nor/swm050.c @@ -156,10 +156,7 @@ COMMAND_HANDLER(swm050_handle_mass_erase_command) FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command) { - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); bank->write_start_alignment = 4; bank->write_end_alignment = 4; bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES; diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index 4b8d2208a..611688c6a 100644 --- a/src/flash/nor/tms470.c +++ b/src/flash/nor/tms470.c @@ -148,11 +148,9 @@ static int tms470_read_part_info(struct flash_bank *bank) rom_flash = (device_ident_reg >> 10) & 1; part_number = (device_ident_reg >> 3) & 0x7f; - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - bank->num_sectors = 0; - } + free(bank->sectors); + bank->sectors = NULL; + bank->num_sectors = 0; /* * If the part number is known, determine if the flash bank is valid diff --git a/src/flash/nor/w600.c b/src/flash/nor/w600.c index 479082177..043959326 100644 --- a/src/flash/nor/w600.c +++ b/src/flash/nor/w600.c @@ -331,10 +331,8 @@ static int w600_probe(struct flash_bank *bank) /* check that calculation result makes sense */ assert(num_pages > 0); - if (bank->sectors) { - free(bank->sectors); - bank->sectors = NULL; - } + free(bank->sectors); + bank->sectors = NULL; bank->base = W600_FLASH_BASE; bank->size = num_pages * W600_FLASH_SECSIZE; commit 47d29ebe11babdddd107ba5edab7e5cd85ce1fee Author: Antonio Borneo <bor...@gm...> Date: Fri Aug 14 10:54:32 2020 +0200 adi_v5: use macro DP_APSEL_MAX to allocate struct adiv5_ap Commit 11019a824d02 ("adi_v5: enforce check on AP number value") introduces the macro DP_APSEL_MAX and use it in place of hardcoded magic numbers for the upper limit of AP selection value. Use the macro also while defining the array of struct adiv5_ap in struct adiv5_dap. Change-Id: I88f53ceb710f92a48a8026a365709fbf2d9e6912 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5806 Tested-by: jenkins diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h index 17365bddb..ea7155167 100644 --- a/src/target/arm_adi_v5.h +++ b/src/target/arm_adi_v5.h @@ -253,7 +253,7 @@ struct adiv5_dap { /* Control config */ uint32_t dp_ctrl_stat; - struct adiv5_ap ap[256]; + struct adiv5_ap ap[DP_APSEL_MAX + 1]; /* The current manually selected AP by the "dap apsel" command */ uint32_t apsel; ----------------------------------------------------------------------- Summary of changes: src/flash/nand/fileio.c | 13 ++++---- src/flash/nor/ambiqmicro.c | 5 +--- src/flash/nor/at91sam3.c | 3 +- src/flash/nor/at91sam4.c | 3 +- src/flash/nor/at91samd.c | 4 +-- src/flash/nor/atsame5.c | 4 +-- src/flash/nor/avrf.c | 5 +--- src/flash/nor/cc3220sf.c | 5 +--- src/flash/nor/cfi.c | 23 ++++++-------- src/flash/nor/efm32.c | 10 ++----- src/flash/nor/em357.c | 5 +--- src/flash/nor/kinetis.c | 13 ++++---- src/flash/nor/kinetis_ke.c | 5 +--- src/flash/nor/max32xxx.c | 5 +--- src/flash/nor/mdr.c | 8 ++--- src/flash/nor/msp432.c | 8 ++--- src/flash/nor/niietcm4.c | 11 +++---- src/flash/nor/pic32mx.c | 8 ++--- src/flash/nor/psoc4.c | 11 ++----- src/flash/nor/psoc6.c | 6 ++-- src/flash/nor/sim3x.c | 5 +--- src/flash/nor/stellaris.c | 5 +--- src/flash/nor/stm32f1x.c | 16 ++++------ src/flash/nor/stm32f2x.c | 16 ++++------ src/flash/nor/stm32h7x.c | 6 ++-- src/flash/nor/stm32l4x.c | 5 +--- src/flash/nor/stm32lx.c | 5 +--- src/flash/nor/swm050.c | 5 +--- src/flash/nor/tms470.c | 8 ++--- src/flash/nor/w600.c | 6 ++-- src/helper/ioutil.c | 3 +- src/rtos/chibios.c | 6 ++-- src/rtos/linux.c | 12 +++----- src/rtos/rtos.c | 11 +++---- src/server/gdb_server.c | 10 ++----- src/server/server.c | 11 ++----- src/server/telnet_server.c | 25 +++++----------- src/svf/svf.c | 74 +++++++++++++++++++--------------------------- src/target/arm_adi_v5.h | 2 +- src/xsvf/xsvf.c | 20 ++++--------- 40 files changed, 133 insertions(+), 273 deletions(-) hooks/post-receive -- Main OpenOCD repository |