hv: instr_emul: refine decode_prefixes to one exit point
Misra C requires Function must have only one return entry.
Acked-by: Eddie Dong
@@ -1698,16 +1698,16 @@ static bool segment_override(uint8_t x, enum cpu_reg_name *seg)
return override;
}
-static int32_t decode_prefixes(struct instr_emul_vie *vie,
- enum vm_cpu_mode cpu_mode, bool cs_d)
+static int32_t decode_prefixes(struct instr_emul_vie *vie, enum vm_cpu_mode cpu_mode, bool cs_d)
{
uint8_t x, i;
+ int32_t ret = 0;
for (i = 0U; i < VIE_PREFIX_SIZE; i++) {
if (vie_peek(vie, &x) != 0) {
- return -1;
- }
-
+ ret = -1;
+ break;
+ } else {
if (x == 0x66U) {
vie->opsize_override = 1U;
} else if (x == 0x67U) {
@@ -1724,7 +1724,9 @@ static int32_t decode_prefixes(struct instr_emul_vie *vie,
vie_advance(vie);
}
+ }
+ if (ret == 0) {
/*
* From section 2.2.1, "REX Prefixes", Intel SDM Vol 2:
* - Only one REX prefix is allowed per instruction.
@@ -1767,7 +1769,9 @@ static int32_t decode_prefixes(struct instr_emul_vie *vie,
vie->addrsize = vie->addrsize_override != 0U ? 4U : 2U;
vie->opsize = vie->opsize_override != 0U ? 4U : 2U;
}
- return 0;
+ }
+
+ return ret;
}
static int32_t decode_two_byte_opcode(struct instr_emul_vie *vie)
