From 32239cf55f0a630fb6698dec03b566a53986c19d Mon Sep 17 00:00:00 2001 From: "Yan, Like" Date: Tue, 11 Jun 2019 19:52:45 +0800 Subject: [PATCH] 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 --- hypervisor/arch/x86/guest/vm.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 06d426b42..9f290c64a 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -393,6 +393,21 @@ static void prepare_epc_vm_memmap(struct acrn_vm *vm) } } +static void register_pm_io_handler(struct acrn_vm *vm) +{ + if (is_sos_vm(vm)) { + /* Load pm S state data */ + if (vm_load_pm_s_state(vm) == 0) { + register_pm1ab_handler(vm); + } + } + + /* Intercept the virtual pm port for RTVM */ + if (is_rt_vm(vm)) { + register_rt_vm_pm1a_ctl_handler(vm); + } +} + /** * @pre vm_id < CONFIG_MAX_VM_NUM && vm_config != NULL && rtn_vm != NULL * @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_ vm_setup_cpu_state(vm); - if (is_sos_vm(vm)) { - /* Load pm S state data */ - if (vm_load_pm_s_state(vm) == 0) { - register_pm1ab_handler(vm); - } - } + register_pm_io_handler(vm); + if (!is_lapic_pt_configured(vm)) { vpic_init(vm); } @@ -501,11 +512,6 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ vioapic_init(vm); } - /* Intercept the virtual pm port for RTVM */ - if (is_rt_vm(vm)) { - register_rt_vm_pm1a_ctl_handler(vm); - } - /* Populate return VM handle */ *rtn_vm = vm; vm->sw.io_shared_page = NULL;