Skip to content

Commit d40061a

Browse files
LucienDufoursobuch
authored andcommitted
Use C99 style for loop var
Use ARRAY_SIZE() to ensure ranges are correct. Also, the C99 style is hopefully more readable. Change-Id: I3d6bfbdc8e723791ba14d5a32e311c61bc2dfd77 Signed-off-by: Lucien Dufour <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/9097 Reviewed-by: Tomas Vanek <[email protected]> Tested-by: jenkins Reviewed-by: zapb <[email protected]>
1 parent 7ed84ec commit d40061a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/target/armv4_5.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,14 @@ static const struct reg_arch_type arm_reg_type = {
659659

660660
struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
661661
{
662-
int num_regs = ARRAY_SIZE(arm_core_regs);
663-
int num_core_regs = num_regs;
662+
unsigned int num_regs = ARRAY_SIZE(arm_core_regs);
663+
unsigned int num_core_regs = num_regs;
664664
if (arm->arm_vfp_version == ARM_VFP_V3)
665665
num_regs += ARRAY_SIZE(arm_vfp_v3_regs);
666666

667667
struct reg_cache *cache = malloc(sizeof(struct reg_cache));
668668
struct reg *reg_list = calloc(num_regs, sizeof(struct reg));
669669
struct arm_reg *reg_arch_info = calloc(num_regs, sizeof(struct arm_reg));
670-
int i;
671670

672671
if (!cache || !reg_list || !reg_arch_info) {
673672
free(cache);
@@ -681,7 +680,7 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
681680
cache->reg_list = reg_list;
682681
cache->num_regs = 0;
683682

684-
for (i = 0; i < num_core_regs; i++) {
683+
for (unsigned int i = 0; i < num_core_regs; i++) {
685684
/* Skip registers this core doesn't expose */
686685
if (arm_core_regs[i].mode == ARM_MODE_MON
687686
&& arm->core_type != ARM_CORE_TYPE_SEC_EXT
@@ -737,8 +736,7 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
737736
cache->num_regs++;
738737
}
739738

740-
int j;
741-
for (i = num_core_regs, j = 0; i < num_regs; i++, j++) {
739+
for (unsigned int i = num_core_regs, j = 0; i < num_regs; i++, j++) {
742740
reg_arch_info[i].num = arm_vfp_v3_regs[j].id;
743741
reg_arch_info[i].mode = arm_vfp_v3_regs[j].mode;
744742
reg_arch_info[i].target = target;
@@ -1413,7 +1411,6 @@ int armv4_5_run_algorithm_inner(struct target *target,
14131411
uint32_t context[17];
14141412
uint32_t cpsr;
14151413
int exit_breakpoint_size = 0;
1416-
int i;
14171414
int retval = ERROR_OK;
14181415

14191416
LOG_TARGET_DEBUG(target, "Running algorithm");
@@ -1442,7 +1439,7 @@ int armv4_5_run_algorithm_inner(struct target *target,
14421439
/* save r0..pc, cpsr-or-spsr, and then cpsr-for-sure;
14431440
* they'll be restored later.
14441441
*/
1445-
for (i = 0; i <= 16; i++) {
1442+
for (unsigned int i = 0; i < ARRAY_SIZE(context); i++) {
14461443
struct reg *r;
14471444

14481445
r = &ARMV4_5_CORE_REG_MODE(arm->core_cache,
@@ -1454,7 +1451,7 @@ int armv4_5_run_algorithm_inner(struct target *target,
14541451
}
14551452
cpsr = buf_get_u32(arm->cpsr->value, 0, 32);
14561453

1457-
for (i = 0; i < num_mem_params; i++) {
1454+
for (int i = 0; i < num_mem_params; i++) {
14581455
if (mem_params[i].direction == PARAM_IN)
14591456
continue;
14601457
retval = target_write_buffer(target, mem_params[i].address, mem_params[i].size,
@@ -1463,7 +1460,7 @@ int armv4_5_run_algorithm_inner(struct target *target,
14631460
return retval;
14641461
}
14651462

1466-
for (i = 0; i < num_reg_params; i++) {
1463+
for (int i = 0; i < num_reg_params; i++) {
14671464
if (reg_params[i].direction == PARAM_IN)
14681465
continue;
14691466

@@ -1524,7 +1521,7 @@ int armv4_5_run_algorithm_inner(struct target *target,
15241521
if (retval != ERROR_OK)
15251522
return retval;
15261523

1527-
for (i = 0; i < num_mem_params; i++) {
1524+
for (int i = 0; i < num_mem_params; i++) {
15281525
if (mem_params[i].direction != PARAM_OUT) {
15291526
int retvaltemp = target_read_buffer(target, mem_params[i].address,
15301527
mem_params[i].size,
@@ -1534,7 +1531,7 @@ int armv4_5_run_algorithm_inner(struct target *target,
15341531
}
15351532
}
15361533

1537-
for (i = 0; i < num_reg_params; i++) {
1534+
for (int i = 0; i < num_reg_params; i++) {
15381535
if (reg_params[i].direction != PARAM_OUT) {
15391536

15401537
struct reg *reg = register_get_by_name(arm->core_cache,
@@ -1559,7 +1556,7 @@ int armv4_5_run_algorithm_inner(struct target *target,
15591556
}
15601557

15611558
/* restore everything we saved before (17 or 18 registers) */
1562-
for (i = 0; i <= 16; i++) {
1559+
for (unsigned int i = 0; i < ARRAY_SIZE(context); i++) {
15631560
uint32_t regvalue;
15641561
regvalue = buf_get_u32(ARMV4_5_CORE_REG_MODE(arm->core_cache,
15651562
arm_algorithm_info->core_mode, i).value, 0, 32);

0 commit comments

Comments
 (0)