openocd: use macro ARRAY_SIZE()

There are still few cases where the macro ARRAY_SIZE() should be
used in place of custom code.

Use ARRAY_SIZE() whenever possible.

Change-Id: Iba0127a02357bc704fe639e08562a4f9aa7011df
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6260
Reviewed-by: Xiang W <wxjstz@126.com>
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2020-08-24 11:42:15 +02:00
parent 8f6dd512c7
commit 8446e14018
5 changed files with 8 additions and 10 deletions

View File

@ -335,7 +335,7 @@ static int psoc4_sysreq(struct flash_bank *bank, uint8_t cmd,
/* Execute wait code */ /* Execute wait code */
retval = target_run_algorithm(target, 0, NULL, retval = target_run_algorithm(target, 0, NULL,
sizeof(reg_params) / sizeof(*reg_params), reg_params, ARRAY_SIZE(reg_params), reg_params,
sysreq_wait_algorithm->address, 0, 1000, &armv7m_info); sysreq_wait_algorithm->address, 0, 1000, &armv7m_info);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
LOG_ERROR("sysreq wait code execution failed"); LOG_ERROR("sysreq wait code execution failed");

View File

@ -533,8 +533,8 @@ static int stm32lx_write_half_pages(struct flash_bank *bank, const uint8_t *buff
buf_set_u32(reg_params[2].value, 0, 32, this_count / 4); buf_set_u32(reg_params[2].value, 0, 32, this_count / 4);
/* 5: Execute the bunch of code */ /* 5: Execute the bunch of code */
retval = target_run_algorithm(target, 0, NULL, sizeof(reg_params) retval = target_run_algorithm(target, 0, NULL,
/ sizeof(*reg_params), reg_params, ARRAY_SIZE(reg_params), reg_params,
write_algorithm->address, 0, 10000, &armv7m_info); write_algorithm->address, 0, 10000, &armv7m_info);
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;

View File

@ -356,7 +356,7 @@ static bool usb_connect(void)
/* Check for device vid/pid match */ /* Check for device vid/pid match */
libusb_get_device_descriptor(list[i], &desc); libusb_get_device_descriptor(list[i], &desc);
match = false; match = false;
for (device = 0; device < sizeof(vids)/sizeof(vids[0]); device++) { for (device = 0; device < ARRAY_SIZE(vids); device++) {
if (desc.idVendor == vids[device] && if (desc.idVendor == vids[device] &&
desc.idProduct == pids[device]) { desc.idProduct == pids[device]) {
match = true; match = true;

View File

@ -267,8 +267,7 @@ static int mqx_create(
) )
{ {
/* check target name against supported architectures */ /* check target name against supported architectures */
int mqx_params_list_num = (sizeof(mqx_params_list)/sizeof(struct mqx_params)); for (unsigned int i = 0; i < ARRAY_SIZE(mqx_params_list); i++) {
for (int i = 0; i < mqx_params_list_num; i++) {
if (0 == strcmp(mqx_params_list[i].target_name, target->type->name)) { if (0 == strcmp(mqx_params_list[i].target_name, target->type->name)) {
target->rtos->rtos_specific_params = (void *)&mqx_params_list[i]; target->rtos->rtos_specific_params = (void *)&mqx_params_list[i];
/* LOG_DEBUG("MQX RTOS - valid architecture: %s", target->type->name); */ /* LOG_DEBUG("MQX RTOS - valid architecture: %s", target->type->name); */
@ -351,7 +350,7 @@ static int mqx_update_threads(
uint8_t task_name[MQX_THREAD_NAME_LENGTH + 1]; uint8_t task_name[MQX_THREAD_NAME_LENGTH + 1];
uint32_t task_addr = 0, task_template = 0, task_state = 0; uint32_t task_addr = 0, task_template = 0, task_state = 0;
uint32_t task_name_addr = 0, task_id = 0, task_errno = 0; uint32_t task_name_addr = 0, task_id = 0, task_errno = 0;
uint32_t state_index = 0, state_max = 0; uint32_t state_index = 0;
uint32_t extra_info_length = 0; uint32_t extra_info_length = 0;
char *state_name = "Unknown"; char *state_name = "Unknown";
@ -412,8 +411,7 @@ static int mqx_update_threads(
} }
task_state &= MQX_TASK_STATE_MASK; task_state &= MQX_TASK_STATE_MASK;
/* and search for defined state */ /* and search for defined state */
state_max = (sizeof(mqx_states)/sizeof(struct mqx_state)); for (state_index = 0; state_index < ARRAY_SIZE(mqx_states); state_index++) {
for (state_index = 0; (state_index < state_max); state_index++) {
if (mqx_states[state_index].state == task_state) { if (mqx_states[state_index].state == task_state) {
state_name = mqx_states[state_index].name; state_name = mqx_states[state_index].name;
break; break;

View File

@ -314,7 +314,7 @@ static int nuttx_update_threads(struct rtos *rtos)
state = tcb.dat[state_offset - 8]; state = tcb.dat[state_offset - 8];
thread->extra_info_str = NULL; thread->extra_info_str = NULL;
if (state < sizeof(task_state_str)/sizeof(char *)) { if (state < ARRAY_SIZE(task_state_str)) {
thread->extra_info_str = malloc(256); thread->extra_info_str = malloc(256);
snprintf(thread->extra_info_str, 256, "pid:%d, %s", snprintf(thread->extra_info_str, 256, "pid:%d, %s",
tcb.dat[pid_offset - 8] | tcb.dat[pid_offset - 8] |