mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-21 19:01:55 +00:00
hv: io: fix MISRA-C violations related to multiple exits
This patch fixes the MISRA-C violations in arch/x86/io.c. * make the function have only one exit point v1 -> v2: * replace `ASSERT` with `pr_err` Tracked-On: #861 Signed-off-by: Shiqing Gao <shiqing.gao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
c03bad1fef
commit
56af4332e3
@ -136,20 +136,14 @@ static void io_instr_dest_handler(struct io_request *io_req)
|
|||||||
*/
|
*/
|
||||||
void emulate_io_post(struct acrn_vcpu *vcpu)
|
void emulate_io_post(struct acrn_vcpu *vcpu)
|
||||||
{
|
{
|
||||||
if (get_vhm_req_state(vcpu->vm, vcpu->vcpu_id)
|
if (get_vhm_req_state(vcpu->vm, vcpu->vcpu_id) == REQ_STATE_COMPLETE) {
|
||||||
!= REQ_STATE_COMPLETE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If vcpu is in Zombie state and will be destroyed soon. Just
|
* If vcpu is in Zombie state and will be destroyed soon. Just
|
||||||
* mark ioreq done and don't resume vcpu.
|
* mark ioreq done and don't resume vcpu.
|
||||||
*/
|
*/
|
||||||
if (vcpu->state == VCPU_ZOMBIE) {
|
if (vcpu->state == VCPU_ZOMBIE) {
|
||||||
complete_ioreq(vcpu, NULL);
|
complete_ioreq(vcpu, NULL);
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
switch (vcpu->req.type) {
|
switch (vcpu->req.type) {
|
||||||
case REQ_MMIO:
|
case REQ_MMIO:
|
||||||
request_vcpu_pre_work(vcpu, ACRN_VCPU_MMIO_COMPLETE);
|
request_vcpu_pre_work(vcpu, ACRN_VCPU_MMIO_COMPLETE);
|
||||||
@ -157,7 +151,8 @@ void emulate_io_post(struct acrn_vcpu *vcpu)
|
|||||||
|
|
||||||
case REQ_PORTIO:
|
case REQ_PORTIO:
|
||||||
case REQ_PCICFG:
|
case REQ_PCICFG:
|
||||||
/* REQ_PORTIO on 0xcf8 & 0xcfc may switch to REQ_PCICFG in some
|
/*
|
||||||
|
* REQ_PORTIO on 0xcf8 & 0xcfc may switch to REQ_PCICFG in some
|
||||||
* cases. It works to apply the post-work for REQ_PORTIO on
|
* cases. It works to apply the post-work for REQ_PORTIO on
|
||||||
* REQ_PCICFG because the format of the first 28 bytes of
|
* REQ_PCICFG because the format of the first 28 bytes of
|
||||||
* REQ_PORTIO & REQ_PCICFG requests are exactly the same and
|
* REQ_PORTIO & REQ_PCICFG requests are exactly the same and
|
||||||
@ -167,14 +162,18 @@ void emulate_io_post(struct acrn_vcpu *vcpu)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* REQ_WP can only be triggered on writes which do not need
|
/*
|
||||||
* post-work. Just mark the ioreq done. */
|
* REQ_WP can only be triggered on writes which do not need
|
||||||
|
* post-work. Just mark the ioreq done.
|
||||||
|
*/
|
||||||
complete_ioreq(vcpu, NULL);
|
complete_ioreq(vcpu, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
resume_vcpu(vcpu);
|
resume_vcpu(vcpu);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try handling the given request by any port I/O handler registered in the
|
* Try handling the given request by any port I/O handler registered in the
|
||||||
@ -257,7 +256,8 @@ hv_emulate_mmio(struct acrn_vcpu *vcpu, struct io_request *io_req)
|
|||||||
continue;
|
continue;
|
||||||
} else if (!((address >= base) && ((address + size) <= end))) {
|
} else if (!((address >= base) && ((address + size) <= end))) {
|
||||||
pr_fatal("Err MMIO, address:0x%llx, size:%x", address, size);
|
pr_fatal("Err MMIO, address:0x%llx, size:%x", address, size);
|
||||||
return -EIO;
|
status = -EIO;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* Handle this MMIO operation */
|
/* Handle this MMIO operation */
|
||||||
if (mmio_handler->read_write != NULL) {
|
if (mmio_handler->read_write != NULL) {
|
||||||
@ -483,17 +483,13 @@ int32_t register_mmio_emulation_handler(struct acrn_vm *vm,
|
|||||||
struct mem_io_node *mmio_node;
|
struct mem_io_node *mmio_node;
|
||||||
|
|
||||||
if ((vm->hw.created_vcpus > 0U) && (vm->hw.vcpu_array[0].launched)) {
|
if ((vm->hw.created_vcpus > 0U) && (vm->hw.vcpu_array[0].launched)) {
|
||||||
ASSERT(false, "register mmio handler after vm launched");
|
pr_err("register mmio handler after vm launched");
|
||||||
return status;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
/* Ensure both a read/write handler and range check function exist */
|
/* Ensure both a read/write handler and range check function exist */
|
||||||
if ((read_write != NULL) && (end > start)) {
|
if ((read_write != NULL) && (end > start)) {
|
||||||
|
|
||||||
if (vm->emul_mmio_regions >= CONFIG_MAX_EMULATED_MMIO_REGIONS) {
|
if (vm->emul_mmio_regions >= CONFIG_MAX_EMULATED_MMIO_REGIONS) {
|
||||||
pr_err("the emulated mmio region is out of range");
|
pr_err("the emulated mmio region is out of range");
|
||||||
return status;
|
} else {
|
||||||
}
|
|
||||||
mmio_node = &(vm->emul_mmio[vm->emul_mmio_regions]);
|
mmio_node = &(vm->emul_mmio[vm->emul_mmio_regions]);
|
||||||
/* Fill in information for this node */
|
/* Fill in information for this node */
|
||||||
mmio_node->read_write = read_write;
|
mmio_node->read_write = read_write;
|
||||||
@ -509,13 +505,13 @@ int32_t register_mmio_emulation_handler(struct acrn_vm *vm,
|
|||||||
* need to unmap it.
|
* need to unmap it.
|
||||||
*/
|
*/
|
||||||
if (is_vm0(vm)) {
|
if (is_vm0(vm)) {
|
||||||
ept_mr_del(vm, (uint64_t *)vm->arch_vm.nworld_eptp,
|
ept_mr_del(vm, (uint64_t *)vm->arch_vm.nworld_eptp, start, end - start);
|
||||||
start, end - start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
status = 0;
|
status = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return status to caller */
|
/* Return status to caller */
|
||||||
|
Loading…
Reference in New Issue
Block a user