mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-22 17:27:53 +00:00
hv: fix the vm pointer check before use
After using get_vm_from_vmid(), vm pointer is always not NULL. But there are still many NULL pointer checks. This commit replaced the NULL vm pointer check with a validation check which checks the vm status. In addition, NULL check for pointer returned by get_sos_vm() and get_vm_config() is removed. Tracked-On: #2520 Signed-off-by: Yan, Like <like.yan@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
committed by
ACRN System Integration
parent
275625af16
commit
ede1459e19
@@ -53,6 +53,7 @@ static struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE)
|
||||
|
||||
/*
|
||||
* @pre vm_id < CONFIG_MAX_VM_NUM
|
||||
* @post return != NULL
|
||||
*/
|
||||
struct acrn_vm_config *get_vm_config(uint16_t vm_id)
|
||||
{
|
||||
|
@@ -48,18 +48,24 @@ uint16_t find_free_vm_id(void)
|
||||
return (vm_config->type == UNDEFINED_VM) ? id : INVALID_VM_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @pre vm != NULL && vm->vmid < CONFIG_MAX_VM_NUM
|
||||
*/
|
||||
static inline void free_vm_id(const struct acrn_vm *vm)
|
||||
{
|
||||
struct acrn_vm_config *vm_config = get_vm_config(vm->vm_id);
|
||||
|
||||
if (vm_config != NULL) {
|
||||
vm_config->type = UNDEFINED_VM;
|
||||
}
|
||||
vm_config->type = UNDEFINED_VM;
|
||||
}
|
||||
|
||||
bool is_valid_vm(const struct acrn_vm *vm)
|
||||
{
|
||||
return (vm != NULL) && (vm->state != VM_STATE_INVALID);
|
||||
}
|
||||
|
||||
bool is_sos_vm(const struct acrn_vm *vm)
|
||||
{
|
||||
return (vm != NULL) && (vm == sos_vm_ptr);
|
||||
return (vm != NULL) && (get_vm_config(vm->vm_id)->type == SOS_VM);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,7 +453,7 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
|
||||
}
|
||||
}
|
||||
|
||||
if (need_cleanup && (vm != NULL)) {
|
||||
if (need_cleanup && is_valid_vm(vm)) {
|
||||
if (vm->arch_vm.nworld_eptp != NULL) {
|
||||
(void)memset(vm->arch_vm.nworld_eptp, 0U, PAGE_SIZE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user