target: prepare for aligning switch and case statements

To prepare for aligning switch and case statements, fix in advance
some checkpatch error due to existing code:
- remove useless parenthesis;
- remove useless 'break';
- join spit lines;
- add space around operators;
- remove 'else' after exit() and return.

Change-Id: I8a87a0ea104205d087dcb8cbf4c67ff13a47742f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9050
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
This commit is contained in:
Antonio Borneo
2025-07-26 13:41:04 +02:00
parent 6b7cc918f0
commit e9561c4af5
8 changed files with 82 additions and 100 deletions

View File

@@ -838,7 +838,6 @@ static int arm11_read_memory_inner(struct target *target,
break;
case 2:
{
arm11->arm.core_cache->reg_list[1].dirty = true;
for (size_t i = 0; i < count; i++) {
@@ -856,7 +855,6 @@ static int arm11_read_memory_inner(struct target *target,
}
break;
}
case 4:
{
@@ -928,7 +926,6 @@ static int arm11_write_memory_inner(struct target *target,
switch (size) {
case 1:
{
arm11->arm.core_cache->reg_list[1].dirty = true;
for (size_t i = 0; i < count; i++) {
@@ -948,10 +945,8 @@ static int arm11_write_memory_inner(struct target *target,
}
break;
}
case 2:
{
arm11->arm.core_cache->reg_list[1].dirty = true;
for (size_t i = 0; i < count; i++) {
@@ -974,9 +969,9 @@ static int arm11_write_memory_inner(struct target *target,
}
break;
}
case 4: {
case 4:
{
/* stream word data through DCC directly to memory */
/* increment: STC p14,c5,[R0],#4 */
/* no increment: STC p14,c5,[R0]*/

View File

@@ -2329,9 +2329,9 @@ int arm7_9_write_memory(struct target *target,
/* fast memory writes are only safe when the target is running
* from a sufficiently high clock (32 kHz is usually too slow)
*/
if (arm7_9->fast_memory_access)
if (arm7_9->fast_memory_access) {
retval = arm7_9_execute_fast_sys_speed(target);
else {
} else {
retval = arm7_9_execute_sys_speed(target);
/*
@@ -2373,9 +2373,9 @@ int arm7_9_write_memory(struct target *target,
/* fast memory writes are only safe when the target is running
* from a sufficiently high clock (32 kHz is usually too slow)
*/
if (arm7_9->fast_memory_access)
if (arm7_9->fast_memory_access) {
retval = arm7_9_execute_fast_sys_speed(target);
else {
} else {
retval = arm7_9_execute_sys_speed(target);
/*
@@ -2416,9 +2416,9 @@ int arm7_9_write_memory(struct target *target,
/* fast memory writes are only safe when the target is running
* from a sufficiently high clock (32 kHz is usually too slow)
*/
if (arm7_9->fast_memory_access)
if (arm7_9->fast_memory_access) {
retval = arm7_9_execute_fast_sys_speed(target);
else {
} else {
retval = arm7_9_execute_sys_speed(target);
/*

View File

@@ -816,11 +816,9 @@ static int dsp563xx_write_register(struct target *target, int num, int force)
arch_info->instr_mask,
dsp563xx->core_regs[num]);
if ((err == ERROR_OK) && (arch_info->num == DSP563XX_REG_IDX_SP)) {
dsp563xx->core_cache->reg_list[DSP563XX_REG_IDX_SSH].valid =
0;
dsp563xx->core_cache->reg_list[DSP563XX_REG_IDX_SSL].valid =
0;
if (err == ERROR_OK && arch_info->num == DSP563XX_REG_IDX_SP) {
dsp563xx->core_cache->reg_list[DSP563XX_REG_IDX_SSH].valid = 0;
dsp563xx->core_cache->reg_list[DSP563XX_REG_IDX_SSL].valid = 0;
}
break;

View File

@@ -933,7 +933,6 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio
ctx->current_pc = ctx->last_branch;
ctx->pipe_index++;
continue;
break;
case 0x2: /* trace restarted after FIFO overflow */
command_print(cmd,
"--- trace restarted after FIFO overflow at 0x%8.8" PRIx32 " ---",
@@ -941,7 +940,6 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio
ctx->current_pc = ctx->last_branch;
ctx->pipe_index++;
continue;
break;
case 0x3: /* exit from debug state */
command_print(cmd,
"--- exit from debug state at 0x%8.8" PRIx32 " ---",
@@ -949,7 +947,6 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio
ctx->current_pc = ctx->last_branch;
ctx->pipe_index++;
continue;
break;
case 0x4: /* periodic synchronization point */
next_pc = ctx->last_branch;
/* if we had no valid PC prior to this synchronization point,
@@ -965,8 +962,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocatio
}
break;
default: /* reserved */
LOG_ERROR(
"BUG: branch reason code 0x%" PRIx32 " is reserved",
LOG_ERROR("BUG: branch reason code 0x%" PRIx32 " is reserved",
ctx->last_branch_reason);
return ERROR_FAIL;
}

View File

@@ -119,9 +119,9 @@ static int jsp_input(struct connection *connection)
while (bytes_read) {
switch (t_con->state) {
case TELNET_STATE_DATA:
if (*buf_p == 0xff)
if (*buf_p == 0xff) {
t_con->state = TELNET_STATE_IAC;
else {
} else {
int out_len = 1;
int in_len;
unsigned char in_buffer[10];
@@ -129,8 +129,7 @@ static int jsp_input(struct connection *connection)
&out_len, buf_p, &in_len,
in_buffer);
if (in_len)
telnet_write(connection,
in_buffer, in_len);
telnet_write(connection, in_buffer, in_len);
}
break;
case TELNET_STATE_IAC:

View File

@@ -452,7 +452,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 1, fields);
if (retval != ERROR_OK)
return retval;
else {
{
int fd = semihosting_get_field(target, 0, fields);
/* Do not allow to close OpenOCD's own standard streams */
if (fd == 0 || fd == 1 || fd == 2) {
@@ -554,49 +555,43 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 2, fields);
if (retval != ERROR_OK)
return retval;
else {
int type = semihosting_get_field(target, 0, fields);
int code = semihosting_get_field(target, 1, fields);
if (type == ADP_STOPPED_APPLICATION_EXIT) {
if (!gdb_get_actual_connections())
exit(code);
else {
fprintf(stderr,
"semihosting: *** application exited with %d ***\n",
code);
}
} else {
fprintf(stderr,
"semihosting: application exception %#x\n",
type);
}
int type = semihosting_get_field(target, 0, fields);
int code = semihosting_get_field(target, 1, fields);
if (type == ADP_STOPPED_APPLICATION_EXIT) {
if (!gdb_get_actual_connections())
exit(code);
fprintf(stderr,
"semihosting: *** application exited with %d ***\n",
code);
} else {
fprintf(stderr,
"semihosting: application exception %#x\n", type);
}
} else {
if (semihosting->param == ADP_STOPPED_APPLICATION_EXIT) {
if (!gdb_get_actual_connections())
exit(0);
else {
fprintf(stderr,
"semihosting: *** application exited normally ***\n");
}
fprintf(stderr,
"semihosting: *** application exited normally ***\n");
} else if (semihosting->param == ADP_STOPPED_RUN_TIME_ERROR) {
/* Chosen more or less arbitrarily to have a nicer message,
* otherwise all other return the same exit code 1. */
if (!gdb_get_actual_connections())
exit(1);
else {
fprintf(stderr,
"semihosting: *** application exited with error ***\n");
}
fprintf(stderr,
"semihosting: *** application exited with error ***\n");
} else {
if (!gdb_get_actual_connections())
exit(1);
else {
fprintf(stderr,
"semihosting: application exception %#x\n",
(unsigned) semihosting->param);
}
fprintf(stderr,
"semihosting: application exception %#x\n",
(unsigned int)semihosting->param);
}
}
if (!semihosting->has_resumable_exit) {
@@ -645,21 +640,20 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 2, fields);
if (retval != ERROR_OK)
return retval;
else {
{
int type = semihosting_get_field(target, 0, fields);
int code = semihosting_get_field(target, 1, fields);
if (type == ADP_STOPPED_APPLICATION_EXIT) {
if (!gdb_get_actual_connections())
exit(code);
else {
fprintf(stderr,
"semihosting: *** application exited with %d ***\n",
code);
}
fprintf(stderr,
"semihosting: *** application exited with %d ***\n",
code);
} else {
fprintf(stderr, "semihosting: exception %#x\n",
type);
fprintf(stderr, "semihosting: exception %#x\n", type);
}
}
if (!semihosting->has_resumable_exit) {
@@ -691,7 +685,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 1, fields);
if (retval != ERROR_OK)
return retval;
else {
{
int fd = semihosting_get_field(target, 0, fields);
struct stat buf;
semihosting->result = fstat(fd, &buf);
@@ -736,16 +731,16 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 2, fields);
if (retval != ERROR_OK)
return retval;
else {
{
uint64_t addr = semihosting_get_field(target, 0, fields);
size_t size = semihosting_get_field(target, 1, fields);
char *arg = semihosting->cmdline ?
semihosting->cmdline : "";
char *arg = semihosting->cmdline ? semihosting->cmdline : "";
uint32_t len = strlen(arg) + 1;
if (len > size)
if (len > size) {
semihosting->result = -1;
else {
} else {
semihosting_set_field(target, len, 1, fields);
retval = target_write_buffer(target, addr, len,
(uint8_t *)arg);
@@ -784,7 +779,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 1, fields);
if (retval != ERROR_OK)
return retval;
else {
{
uint64_t addr = semihosting_get_field(target, 0, fields);
/* tell the remote we have no idea */
memset(fields, 0, 4 * semihosting->word_size_bytes);
@@ -908,7 +904,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 3, fields);
if (retval != ERROR_OK)
return retval;
else {
{
uint64_t addr = semihosting_get_field(target, 0, fields);
uint32_t mode = semihosting_get_field(target, 1, fields);
size_t len = semihosting_get_field(target, 2, fields);
@@ -1038,7 +1035,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 3, fields);
if (retval != ERROR_OK)
return retval;
else {
{
int fd = semihosting_get_field(target, 0, fields);
uint64_t addr = semihosting_get_field(target, 1, fields);
size_t len = semihosting_get_field(target, 2, fields);
@@ -1117,7 +1115,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 2, fields);
if (retval != ERROR_OK)
return retval;
else {
{
uint64_t addr = semihosting_get_field(target, 0, fields);
size_t len = semihosting_get_field(target, 1, fields);
if (semihosting->is_fileio) {
@@ -1131,9 +1130,7 @@ int semihosting_common(struct target *target)
semihosting->result = -1;
semihosting->sys_errno = ENOMEM;
} else {
retval =
target_read_memory(target, addr, 1, len,
fn);
retval = target_read_memory(target, addr, 1, len, fn);
if (retval != ERROR_OK) {
free(fn);
return retval;
@@ -1171,7 +1168,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 4, fields);
if (retval != ERROR_OK)
return retval;
else {
{
uint64_t addr1 = semihosting_get_field(target, 0, fields);
size_t len1 = semihosting_get_field(target, 1, fields);
uint64_t addr2 = semihosting_get_field(target, 2, fields);
@@ -1192,15 +1190,13 @@ int semihosting_common(struct target *target)
semihosting->result = -1;
semihosting->sys_errno = ENOMEM;
} else {
retval = target_read_memory(target, addr1, 1, len1,
fn1);
retval = target_read_memory(target, addr1, 1, len1, fn1);
if (retval != ERROR_OK) {
free(fn1);
free(fn2);
return retval;
}
retval = target_read_memory(target, addr2, 1, len2,
fn2);
retval = target_read_memory(target, addr2, 1, len2, fn2);
if (retval != ERROR_OK) {
free(fn1);
free(fn2);
@@ -1208,8 +1204,7 @@ int semihosting_common(struct target *target)
}
fn1[len1] = 0;
fn2[len2] = 0;
semihosting->result = rename((char *)fn1,
(char *)fn2);
semihosting->result = rename((char *)fn1, (char *)fn2);
// rename() on Windows returns nonzero on error
if (semihosting->result != 0)
semihosting->sys_errno = errno;
@@ -1246,7 +1241,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 2, fields);
if (retval != ERROR_OK)
return retval;
else {
{
int fd = semihosting_get_field(target, 0, fields);
off_t pos = semihosting_get_field(target, 1, fields);
if (semihosting->is_fileio) {
@@ -1292,7 +1288,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 2, fields);
if (retval != ERROR_OK)
return retval;
else {
{
uint64_t addr = semihosting_get_field(target, 0, fields);
size_t len = semihosting_get_field(target, 1, fields);
if (semihosting->is_fileio) {
@@ -1314,12 +1311,10 @@ int semihosting_common(struct target *target)
if (retval != ERROR_OK) {
free(cmd);
return retval;
} else {
cmd[len] = 0;
semihosting->result = system(
(const char *)cmd);
LOG_DEBUG("system('%s')=%" PRId64, cmd, semihosting->result);
}
cmd[len] = 0;
semihosting->result = system((const char *)cmd);
LOG_DEBUG("system('%s')=%" PRId64, cmd, semihosting->result);
free(cmd);
}
@@ -1374,7 +1369,8 @@ int semihosting_common(struct target *target)
retval = semihosting_read_fields(target, 3, fields);
if (retval != ERROR_OK)
return retval;
else {
{
int fd = semihosting_get_field(target, 0, fields);
uint64_t addr = semihosting_get_field(target, 1, fields);
size_t len = semihosting_get_field(target, 2, fields);
@@ -1634,7 +1630,7 @@ int semihosting_common(struct target *target)
default:
fprintf(stderr, "semihosting: unsupported call %#x\n",
(unsigned) semihosting->op);
(unsigned int)semihosting->op);
semihosting->result = -1;
semihosting->sys_errno = ENOTSUP;
}

View File

@@ -1208,15 +1208,13 @@ static int set_watchpoint(struct target *t, struct watchpoint *wp)
switch (wp->rw) {
case WPT_WRITE:
if (set_debug_regs(t, wp->address, wp_num,
DR7_BP_WRITE, wp->length) != ERROR_OK) {
DR7_BP_WRITE, wp->length) != ERROR_OK)
return ERROR_FAIL;
}
break;
case WPT_ACCESS:
if (set_debug_regs(t, wp->address, wp_num, DR7_BP_READWRITE,
wp->length) != ERROR_OK) {
wp->length) != ERROR_OK)
return ERROR_FAIL;
}
break;
default:
LOG_ERROR("%s only 'access' or 'write' watchpoints are supported", __func__);

View File

@@ -2708,7 +2708,7 @@ static int xscale_analyze_trace(struct target *target, struct command_invocation
case 13: /* Checkpointed Indirect Branch */
xscale_branch_address(trace_data, i, &branch_target);
if ((trace_data->num_checkpoints == 2) && (chkpt == 0))
if (trace_data->num_checkpoints == 2 && chkpt == 0)
chkpt_reg = trace_data->chkpt1; /* 2 chkpts, this is
*oldest */
else
@@ -2719,7 +2719,7 @@ static int xscale_analyze_trace(struct target *target, struct command_invocation
break;
case 12: /* Checkpointed Direct Branch */
if ((trace_data->num_checkpoints == 2) && (chkpt == 0))
if (trace_data->num_checkpoints == 2 && chkpt == 0)
chkpt_reg = trace_data->chkpt1; /* 2 chkpts, this is
*oldest */
else