use ARRAY_SIZE macro
authorZachary T Welch <zw@superlucidity.net>
Wed, 25 Nov 2009 04:32:10 +0000 (20:32 -0800)
committerZachary T Welch <zw@superlucidity.net>
Wed, 25 Nov 2009 18:32:00 +0000 (10:32 -0800)
Search and destroy lingering cases where the ARRAY_SIZE macro should
be used to convey more intrinsic meaning in the OpenOCD code.

src/flash/avrf.c
src/flash/tms470.c
src/jtag/ft2232.c
src/jtag/rlink/rlink_speed_table.c
src/jtag/tcl.c
src/target/armv7m.c
src/target/avrt.c
src/target/mips32_pracc.c
src/target/mips_ejtag.c
src/target/xscale.c

index 1c484643c06b9dd708b8f50855d64eeeb096acfb..687dd4b59ea2acf79bf263bfe9ee47532d938ae4 100644 (file)
@@ -290,7 +290,7 @@ static int avrf_probe(struct flash_bank *bank)
                LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F);
        }
 
-       for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++)
+       for (i = 0; i < (int)ARRAY_SIZE(avft_chips_info); i++)
        {
                if (avft_chips_info[i].chip_id == EXTRACT_PART(device_id))
                {
@@ -369,7 +369,7 @@ static int avrf_info(struct flash_bank *bank, char *buf, int buf_size)
                LOG_ERROR("0x%" PRIx32 " is invalid Manufacturer for avr, 0x%X is expected", EXTRACT_MFG(device_id), 0x1F);
        }
 
-       for (i = 0; i < (int)(sizeof(avft_chips_info) / sizeof(avft_chips_info[0])); i++)
+       for (i = 0; i < (int)ARRAY_SIZE(avft_chips_info); i++)
        {
                if (avft_chips_info[i].chip_id == EXTRACT_PART(device_id))
                {
index 682013ef076983001e910c4dae608407eea2c9b8..59659346971096e10bab562c91dd9b74002293c6 100644 (file)
@@ -46,7 +46,7 @@ const struct flash_sector TMS470R1A256_SECTORS[] = {
 };
 
 #define TMS470R1A256_NUM_SECTORS \
-       (sizeof(TMS470R1A256_SECTORS)/sizeof(TMS470R1A256_SECTORS[0]))
+       ARRAY_SIZE(TMS470R1A256_SECTORS)
 
 const struct flash_sector TMS470R1A288_BANK0_SECTORS[] = {
        {0x00000000, 0x00002000, -1, -1},
@@ -56,7 +56,7 @@ const struct flash_sector TMS470R1A288_BANK0_SECTORS[] = {
 };
 
 #define TMS470R1A288_BANK0_NUM_SECTORS \
-       (sizeof(TMS470R1A288_BANK0_SECTORS)/sizeof(TMS470R1A288_BANK0_SECTORS[0]))
+       ARRAY_SIZE(TMS470R1A288_BANK0_SECTORS)
 
 const struct flash_sector TMS470R1A288_BANK1_SECTORS[] = {
        {0x00040000, 0x00010000, -1, -1},
@@ -66,7 +66,7 @@ const struct flash_sector TMS470R1A288_BANK1_SECTORS[] = {
 };
 
 #define TMS470R1A288_BANK1_NUM_SECTORS \
-       (sizeof(TMS470R1A288_BANK1_SECTORS)/sizeof(TMS470R1A288_BANK1_SECTORS[0]))
+       ARRAY_SIZE(TMS470R1A288_BANK1_SECTORS)
 
 const struct flash_sector TMS470R1A384_BANK0_SECTORS[] = {
        {0x00000000, 0x00002000, -1, -1},
@@ -82,7 +82,7 @@ const struct flash_sector TMS470R1A384_BANK0_SECTORS[] = {
 };
 
 #define TMS470R1A384_BANK0_NUM_SECTORS \
-       (sizeof(TMS470R1A384_BANK0_SECTORS)/sizeof(TMS470R1A384_BANK0_SECTORS[0]))
+       ARRAY_SIZE(TMS470R1A384_BANK0_SECTORS)
 
 const struct flash_sector TMS470R1A384_BANK1_SECTORS[] = {
        {0x00020000, 0x00008000, -1, -1},
@@ -92,7 +92,7 @@ const struct flash_sector TMS470R1A384_BANK1_SECTORS[] = {
 };
 
 #define TMS470R1A384_BANK1_NUM_SECTORS \
-       (sizeof(TMS470R1A384_BANK1_SECTORS)/sizeof(TMS470R1A384_BANK1_SECTORS[0]))
+       ARRAY_SIZE(TMS470R1A384_BANK1_SECTORS)
 
 const struct flash_sector TMS470R1A384_BANK2_SECTORS[] = {
        {0x00040000, 0x00008000, -1, -1},
@@ -102,7 +102,7 @@ const struct flash_sector TMS470R1A384_BANK2_SECTORS[] = {
 };
 
 #define TMS470R1A384_BANK2_NUM_SECTORS \
-       (sizeof(TMS470R1A384_BANK2_SECTORS)/sizeof(TMS470R1A384_BANK2_SECTORS[0]))
+       ARRAY_SIZE(TMS470R1A384_BANK2_SECTORS)
 
 /* ---------------------------------------------------------------------- */
 
index 73cbaf3c626730845f618e33ea3e554ab757c9a7..29b6389ced29d94a6fe7962f0feafb374a2b608a 100644 (file)
@@ -1949,7 +1949,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
        {
                static const char* type_str[] =
                        {"BM", "AM", "100AX", "UNKNOWN", "2232C", "232R", "2232H", "4232H"};
-               unsigned no_of_known_types = sizeof(type_str) / sizeof(type_str[0]) - 1;
+               unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1;
                unsigned type_index = ((unsigned)ftdi_device <= no_of_known_types)
                        ? ftdi_device : FT_DEVICE_UNKNOWN;
                LOG_INFO("device: %lu \"%s\"", ftdi_device, type_str[type_index]);
@@ -2034,7 +2034,7 @@ static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_mo
        ftdi_device = ftdic.type;
        static const char* type_str[] =
                {"AM", "BM", "2232C", "R", "2232H", "4232H", "Unknown"};
-       unsigned no_of_known_types = sizeof(type_str) / sizeof(type_str[0]) - 1;
+       unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1;
        unsigned type_index = ((unsigned)ftdi_device < no_of_known_types)
                ? ftdi_device : no_of_known_types;
        LOG_DEBUG("FTDI chip type: %i \"%s\"", (int)ftdi_device, type_str[type_index]);
index 5c40ab465a855bfea94a7fac2a56968074462a3e..2ef62ee3969fbb81d9078da667c9cf9bd819420a 100644 (file)
@@ -97,5 +97,5 @@ const struct rlink_speed_table rlink_speed_table[] = {{
        dtc_2, sizeof(dtc_2), (ST7_FOSC * 2) / (1000 * 2), 2
 }};
 
-const size_t rlink_speed_table_size = sizeof(rlink_speed_table) / sizeof(*rlink_speed_table);
+const size_t rlink_speed_table_size = ARRAY_SIZE(rlink_speed_table);
 
index bc290788d3b854a16645fc99b7c351129232bb37..e755dd7ef2b7ff983bf892f26ead0b128dd9643c 100644 (file)
@@ -1304,7 +1304,7 @@ static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *ar
 {
        tap_state_t states[8];
 
-       if ((argc < 2) || ((size_t)argc > (sizeof(states)/sizeof(*states) + 1)))
+       if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1)))
        {
                Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
                return JIM_ERR;
index 9d89086eb2d373e54c017c5f226a92309d608579..fc3f47ccdb46e6f58b95e9223198622b972ad29d 100644 (file)
@@ -596,7 +596,7 @@ int armv7m_checksum_memory(struct target *target,
        }
 
        /* convert flash writing code into a buffer in target endianness */
-       for (i = 0; i < (sizeof(cortex_m3_crc_code)/sizeof(uint16_t)); i++)
+       for (i = 0; i < ARRAY_SIZE(cortex_m3_crc_code); i++)
                if ((retval = target_write_u16(target, crc_algorithm->address + i*sizeof(uint16_t), cortex_m3_crc_code[i])) != ERROR_OK)
                {
                        return retval;
@@ -659,7 +659,7 @@ int armv7m_blank_check_memory(struct target *target,
        }
 
        /* convert flash writing code into a buffer in target endianness */
-       for (i = 0; i < (sizeof(erase_check_code)/sizeof(uint16_t)); i++)
+       for (i = 0; i < ARRAY_SIZE(erase_check_code); i++)
                target_write_u16(target, erase_check_algorithm->address + i*sizeof(uint16_t), erase_check_code[i]);
 
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
index dc527f5e5472b6107233d5871ff140376491e95c..6ba620688d2657936e51d1efe701dea38b288f56 100644 (file)
@@ -196,7 +196,7 @@ int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_l
                field[0].num_bits = tap->ir_length;
                field[0].out_value = ir_out;
                field[0].in_value = ir_in;
-               jtag_add_plain_ir_scan(sizeof(field) / sizeof(field[0]), field, jtag_set_end_state(TAP_IDLE));
+               jtag_add_plain_ir_scan(ARRAY_SIZE(field), field, jtag_set_end_state(TAP_IDLE));
        }
 
        return ERROR_OK;
@@ -217,7 +217,7 @@ int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_l
                field[0].num_bits = dr_len;
                field[0].out_value = dr_out;
                field[0].in_value = dr_in;
-               jtag_add_plain_dr_scan(sizeof(field) / sizeof(field[0]), field, jtag_set_end_state(TAP_IDLE));
+               jtag_add_plain_dr_scan(ARRAY_SIZE(field), field, jtag_set_end_state(TAP_IDLE));
        }
 
        return ERROR_OK;
index 4f9a7042276373144d40118593d779abf3a46c39..604d34edbf2524d9183b69740fa6d85f00f1438e 100644 (file)
@@ -348,8 +348,8 @@ int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                param_in[0] = addr;
                param_in[1] = blocksize;
 
-               if ((retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code,
-                       sizeof(param_in)/sizeof(param_in[0]), param_in, blocksize, &buf[bytesread], 1)) != ERROR_OK)
+               if ((retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code,
+                       ARRAY_SIZE(param_in), param_in, blocksize, &buf[bytesread], 1)) != ERROR_OK)
                {
                        return retval;
                }
@@ -387,8 +387,8 @@ int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t
 
        param_in[0] = addr;
 
-       if ((retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code,
-               sizeof(param_in)/sizeof(param_in[0]), param_in, sizeof(uint32_t), buf, 1)) != ERROR_OK)
+       if ((retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code,
+               ARRAY_SIZE(param_in), param_in, sizeof(uint32_t), buf, 1)) != ERROR_OK)
        {
                return retval;
        }
@@ -459,8 +459,8 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                param_in[0] = addr;
                param_in[1] = blocksize;
 
-               mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-                       sizeof(param_in)/sizeof(param_in[0]), param_in, count, param_out, 1);
+               mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+                       ARRAY_SIZE(param_in), param_in, count, param_out, 1);
 
 //             count -= blocksize;
 //             addr += blocksize;
@@ -540,8 +540,8 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou
                param_in[0] = addr;
                param_in[1] = blocksize;
 
-               mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-                       sizeof(param_in)/sizeof(param_in[0]), param_in, count, param_out, 1);
+               mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+                       ARRAY_SIZE(param_in), param_in, count, param_out, 1);
 
 //             count -= blocksize;
 //             addr += blocksize;
@@ -619,7 +619,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c
 
        memcpy(&param_in[2], buf, count * sizeof(uint32_t));
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                count + 2, param_in, 0, NULL, 1);
 
        free(param_in);
@@ -654,8 +654,8 @@ int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_
        param_in[0] = addr;
        param_in[1] = *buf;
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-               sizeof(param_in)/sizeof(param_in[0]),param_in, 0, NULL, 1);
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+               ARRAY_SIZE(param_in),param_in, 0, NULL, 1);
 
        return ERROR_OK;
 }
@@ -714,7 +714,7 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c
                param_in[i + 2] = buf[i];
        }
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                count + 2, param_in, 0, NULL, 1);
 
        free(param_in);
@@ -777,7 +777,7 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                param_in[i + 2] = buf[i];
        }
 
-       retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                count +2, param_in, 0, NULL, 1);
 
        free(param_in);
@@ -851,7 +851,7 @@ int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 
        int retval;
 
-       retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                38, regs, 0, NULL, 1);
 
        return retval;
@@ -928,7 +928,7 @@ int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 
        int retval;
 
-       retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                0, NULL, 38, regs, 1);
 
        return retval;
index 6f06d9a3afc79b2b0964e797459307ac3035d158..68a39faf3d6a81c732d9e2f0612f7d0a96db4956 100644 (file)
@@ -143,7 +143,7 @@ int mips_ejtag_step_enable(struct mips_ejtag *ejtag_info)
                        MIPS32_NOP,
        };
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                0, NULL, 0, NULL, 1);
 
        return ERROR_OK;
@@ -169,7 +169,7 @@ int mips_ejtag_step_disable(struct mips_ejtag *ejtag_info)
                        MIPS32_NOP,
        };
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                0, NULL, 0, NULL, 1);
 
        return ERROR_OK;
@@ -234,7 +234,7 @@ int mips_ejtag_read_debug(struct mips_ejtag *ejtag_info, uint32_t* debug_reg)
                        MIPS32_NOP,
        };
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                0, NULL, 1, debug_reg, 1);
 
        return ERROR_OK;
index e402a11cb1ac24c7a95ef12f436087ea03a78a48..07fcc4c0af42a3ef387ccd1a1bcf1cbb874a7167 100644 (file)
@@ -412,7 +412,7 @@ static int xscale_read_tx(struct target *target, int consume)
                        jtag_add_pathmove(3, path);
                else
                {
-                       jtag_add_pathmove(sizeof(noconsume_path)/sizeof(*noconsume_path), noconsume_path);
+                       jtag_add_pathmove(ARRAY_SIZE(noconsume_path), noconsume_path);
                }
 
                jtag_add_dr_scan(3, fields, jtag_set_end_state(TAP_IDLE));
@@ -2825,7 +2825,7 @@ static void xscale_build_reg_cache(struct target *target)
        struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
        struct xscale_reg *arch_info = malloc(sizeof(xscale_reg_arch_info));
        int i;
-       int num_regs = sizeof(xscale_reg_arch_info) / sizeof(struct xscale_reg);
+       int num_regs = ARRAY_SIZE(xscale_reg_arch_info);
 
        (*cache_p) = armv4_5_build_reg_cache(target, armv4_5);
 

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)