openocd: use macro ARRAY_SIZE() 60/6260/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Mon, 24 Aug 2020 09:42:15 +0000 (11:42 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 29 May 2021 20:33:23 +0000 (21:33 +0100)
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
src/flash/nor/psoc4.c
src/flash/nor/stm32lx.c
src/jtag/drivers/xds110.c
src/rtos/mqx.c
src/rtos/nuttx.c

index b606e18cfeac97597785321ba9afa608e1a24911..3ca1f369c6a2984ade28f3e6fbb6d622cafb56a7 100644 (file)
@@ -335,7 +335,7 @@ static int psoc4_sysreq(struct flash_bank *bank, uint8_t cmd,
 
        /* Execute wait code */
        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);
        if (retval != ERROR_OK) {
                LOG_ERROR("sysreq wait code execution failed");
index 3cb1a499824a23bd0473754b7368559b7743e167..b014d097dc92fbe221f3163699813a71b6c7a1c1 100644 (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);
 
                /* 5: Execute the bunch of code */
-               retval = target_run_algorithm(target, 0, NULL, sizeof(reg_params)
-                               / sizeof(*reg_params), reg_params,
+               retval = target_run_algorithm(target, 0, NULL,
+                               ARRAY_SIZE(reg_params), reg_params,
                                write_algorithm->address, 0, 10000, &armv7m_info);
                if (retval != ERROR_OK)
                        break;
index c49280743afd678d7fcbadf9ea64a7a143e6a940..85a1b81db1339a3b03b35881442bbac5ed388974 100644 (file)
@@ -356,7 +356,7 @@ static bool usb_connect(void)
                        /* Check for device vid/pid match */
                        libusb_get_device_descriptor(list[i], &desc);
                        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] &&
                                        desc.idProduct == pids[device]) {
                                        match = true;
index 22cd721ac3184f8b76d45d8cb080c98026838583..9f895deed656d10ce1c8f319be76c36ee046a23c 100644 (file)
@@ -267,8 +267,7 @@ static int mqx_create(
 )
 {
        /* check target name against supported architectures */
-       int mqx_params_list_num = (sizeof(mqx_params_list)/sizeof(struct mqx_params));
-       for (int i = 0; i < mqx_params_list_num; i++) {
+       for (unsigned int i = 0; i < ARRAY_SIZE(mqx_params_list); i++) {
                if (0 == strcmp(mqx_params_list[i].target_name, target->type->name)) {
                        target->rtos->rtos_specific_params = (void *)&mqx_params_list[i];
                        /* 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];
                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 state_index = 0, state_max = 0;
+               uint32_t state_index = 0;
                uint32_t extra_info_length = 0;
                char *state_name = "Unknown";
 
@@ -412,8 +411,7 @@ static int mqx_update_threads(
                }
                task_state &= MQX_TASK_STATE_MASK;
                /* and search for defined state */
-               state_max = (sizeof(mqx_states)/sizeof(struct mqx_state));
-               for (state_index = 0; (state_index < state_max); state_index++) {
+               for (state_index = 0; state_index < ARRAY_SIZE(mqx_states); state_index++) {
                        if (mqx_states[state_index].state == task_state) {
                                state_name = mqx_states[state_index].name;
                                break;
index 0705b17b3526259cd9441a6ed27f0a6e1ffaabeb..c52547120c1383688324520d6c9819bbab2fdada 100644 (file)
@@ -314,7 +314,7 @@ static int nuttx_update_threads(struct rtos *rtos)
 
                        state = tcb.dat[state_offset - 8];
                        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);
                                snprintf(thread->extra_info_str, 256, "pid:%d, %s",
                                    tcb.dat[pid_offset - 8] |

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)