Skip to content

Commit ecb2ad4

Browse files
committed
RISC-V Semihosting 1 of 3: Remove dead code
Variable `target->semihosting` is always initialized in risv_init_target() to a non-NULL value. For that reason, checks like `if (target->semihosting)` are redundant (dead code). Remove them to not confuse code readers. Replace them by assertions. Change-Id: I85ef52300e240cfcb0119db6169993bc4767de8f Signed-off-by: Jan Matyas <[email protected]>
1 parent f82c5a7 commit ecb2ad4

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/target/riscv/riscv_semihosting.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ void riscv_semihosting_init(struct target *target)
5757
enum semihosting_result riscv_semihosting(struct target *target, int *retval)
5858
{
5959
struct semihosting *semihosting = target->semihosting;
60-
if (!semihosting) {
61-
LOG_TARGET_DEBUG(target, " -> NONE (!semihosting)");
62-
return SEMIHOSTING_NONE;
63-
}
60+
assert(semihosting);
6461

6562
if (!semihosting->is_active) {
6663
LOG_TARGET_DEBUG(target, " -> NONE (!semihosting->is_active)");
@@ -170,19 +167,16 @@ static int riscv_semihosting_setup(struct target *target, int enable)
170167
LOG_TARGET_DEBUG(target, "enable=%d", enable);
171168

172169
struct semihosting *semihosting = target->semihosting;
173-
if (semihosting)
174-
semihosting->setup_time = clock();
170+
assert(semihosting);
175171

172+
semihosting->setup_time = clock();
176173
return ERROR_OK;
177174
}
178175

179176
static int riscv_semihosting_post_result(struct target *target)
180177
{
181178
struct semihosting *semihosting = target->semihosting;
182-
if (!semihosting) {
183-
/* If not enabled, silently ignored. */
184-
return 0;
185-
}
179+
assert(semihosting);
186180

187181
LOG_TARGET_DEBUG(target, "Result: 0x%" PRIx64, semihosting->result);
188182
riscv_reg_set(target, GDB_REGNO_A0, semihosting->result);

0 commit comments

Comments
 (0)