Skip to content

Commit ae144e1

Browse files
taoyuhongwenlingz
authored andcommitted
hv:fix MISRA-C violation in virq.c
The MISRA-C Standards suggests procedures to be single exit Tracked-On: #861 Acked-by: Eddie Dong <eddie.dong@intel.com> Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
1 parent 6641bc7 commit ae144e1

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

hypervisor/arch/x86/virq.c

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -177,59 +177,65 @@ static int32_t vcpu_do_pending_extint(const struct acrn_vcpu *vcpu)
177177
/* SDM Vol3 -6.15, Table 6-4 - interrupt and exception classes */
178178
static int32_t get_excep_class(uint32_t vector)
179179
{
180+
int32_t ret;
181+
180182
if ((vector == IDT_DE) || (vector == IDT_TS) || (vector == IDT_NP) ||
181183
(vector == IDT_SS) || (vector == IDT_GP)) {
182-
return EXCEPTION_CLASS_CONT;
184+
ret = EXCEPTION_CLASS_CONT;
183185
} else if ((vector == IDT_PF) || (vector == IDT_VE)) {
184-
return EXCEPTION_CLASS_PF;
186+
ret = EXCEPTION_CLASS_PF;
185187
} else {
186-
return EXCEPTION_CLASS_BENIGN;
188+
ret = EXCEPTION_CLASS_BENIGN;
187189
}
190+
191+
return ret;
188192
}
189193

190194
int32_t vcpu_queue_exception(struct acrn_vcpu *vcpu, uint32_t vector_arg, uint32_t err_code_arg)
191195
{
192196
struct acrn_vcpu_arch *arch = &vcpu->arch;
193197
uint32_t vector = vector_arg;
194198
uint32_t err_code = err_code_arg;
199+
int32_t ret = 0;
195200

196201
/* VECTOR_INVALID is also greater than 32 */
197202
if (vector >= 32U) {
198203
pr_err("invalid exception vector %d", vector);
199-
return -EINVAL;
200-
}
201-
202-
uint32_t prev_vector =
203-
arch->exception_info.exception;
204-
int32_t new_class, prev_class;
205-
206-
/* SDM vol3 - 6.15, Table 6-5 - conditions for generating a
207-
* double fault */
208-
prev_class = get_excep_class(prev_vector);
209-
new_class = get_excep_class(vector);
210-
if ((prev_vector == IDT_DF) && (new_class != EXCEPTION_CLASS_BENIGN)) {
211-
/* triple fault happen - shutdwon mode */
212-
vcpu_make_request(vcpu, ACRN_REQUEST_TRP_FAULT);
213-
return 0;
214-
} else if (((prev_class == EXCEPTION_CLASS_CONT) && (new_class == EXCEPTION_CLASS_CONT)) ||
215-
((prev_class == EXCEPTION_CLASS_PF) && (new_class != EXCEPTION_CLASS_BENIGN))) {
216-
/* generate double fault */
217-
vector = IDT_DF;
218-
err_code = 0U;
204+
ret = -EINVAL;
219205
} else {
220-
/* Trigger the given exception instead of override it with
221-
* double/triple fault. */
222-
}
223206

224-
arch->exception_info.exception = vector;
207+
uint32_t prev_vector = arch->exception_info.exception;
208+
int32_t new_class, prev_class;
225209

226-
if ((exception_type[vector] & EXCEPTION_ERROR_CODE_VALID) != 0U) {
227-
arch->exception_info.error = err_code;
228-
} else {
229-
arch->exception_info.error = 0U;
210+
/* SDM vol3 - 6.15, Table 6-5 - conditions for generating a
211+
* double fault */
212+
prev_class = get_excep_class(prev_vector);
213+
new_class = get_excep_class(vector);
214+
if ((prev_vector == IDT_DF) && (new_class != EXCEPTION_CLASS_BENIGN)) {
215+
/* triple fault happen - shutdwon mode */
216+
vcpu_make_request(vcpu, ACRN_REQUEST_TRP_FAULT);
217+
} else {
218+
if (((prev_class == EXCEPTION_CLASS_CONT) && (new_class == EXCEPTION_CLASS_CONT)) ||
219+
((prev_class == EXCEPTION_CLASS_PF) && (new_class != EXCEPTION_CLASS_BENIGN))) {
220+
/* generate double fault */
221+
vector = IDT_DF;
222+
err_code = 0U;
223+
} else {
224+
/* Trigger the given exception instead of override it with
225+
* double/triple fault. */
226+
}
227+
228+
arch->exception_info.exception = vector;
229+
230+
if ((exception_type[vector] & EXCEPTION_ERROR_CODE_VALID) != 0U) {
231+
arch->exception_info.error = err_code;
232+
} else {
233+
arch->exception_info.error = 0U;
234+
}
235+
}
230236
}
231237

232-
return 0;
238+
return ret;
233239
}
234240

235241
static void vcpu_inject_exception(struct acrn_vcpu *vcpu, uint32_t vector)

0 commit comments

Comments
 (0)