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.
@@ -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;
