Skip to content

Commit 32239cf

Browse files
lyan3Eddie Dong
authored andcommitted
hv: reduce cyclomatic complexity of create_vm()
This commit extract pm io handler registration code to register_pm_io_handler() to reduce the cyclomatic complexity of create_vm() in order to be complied with MISRA-C rules. Tracked-On: #3227 Signed-off-by: Yan, Like <like.yan@intel.com>
1 parent 771f15c commit 32239cf

File tree

1 file changed

+17
-11
lines changed
  • hypervisor/arch/x86/guest

1 file changed

+17
-11
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,21 @@ static void prepare_epc_vm_memmap(struct acrn_vm *vm)
393393
}
394394
}
395395

396+
static void register_pm_io_handler(struct acrn_vm *vm)
397+
{
398+
if (is_sos_vm(vm)) {
399+
/* Load pm S state data */
400+
if (vm_load_pm_s_state(vm) == 0) {
401+
register_pm1ab_handler(vm);
402+
}
403+
}
404+
405+
/* Intercept the virtual pm port for RTVM */
406+
if (is_rt_vm(vm)) {
407+
register_rt_vm_pm1a_ctl_handler(vm);
408+
}
409+
}
410+
396411
/**
397412
* @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL
398413
* @pre vm->state == VM_POWERED_OFF
@@ -471,12 +486,8 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
471486

472487
vm_setup_cpu_state(vm);
473488

474-
if (is_sos_vm(vm)) {
475-
/* Load pm S state data */
476-
if (vm_load_pm_s_state(vm) == 0) {
477-
register_pm1ab_handler(vm);
478-
}
479-
}
489+
register_pm_io_handler(vm);
490+
480491
if (!is_lapic_pt_configured(vm)) {
481492
vpic_init(vm);
482493
}
@@ -501,11 +512,6 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
501512
vioapic_init(vm);
502513
}
503514

504-
/* Intercept the virtual pm port for RTVM */
505-
if (is_rt_vm(vm)) {
506-
register_rt_vm_pm1a_ctl_handler(vm);
507-
}
508-
509515
/* Populate return VM handle */
510516
*rtn_vm = vm;
511517
vm->sw.io_shared_page = NULL;

0 commit comments

Comments
 (0)