From 65a7be8f52783d4470b15cad6dad47c891d6016c Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Tue, 18 Dec 2018 13:56:51 +0800 Subject: [PATCH] hv:refine alloc_vm_id api Fix violation "procedure has more than one exit point" for this api. Tracked-On: #861 Signed-off-by: Mingqiang Chi Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/vm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 6d2d7b5cd..de8779d36 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -16,19 +16,19 @@ static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE); static uint64_t vmid_bitmap; -/* used for vmid allocation. And this means the max vm number is 64 */ static inline uint16_t alloc_vm_id(void) { uint16_t id = ffz64(vmid_bitmap); - while (id < (size_t)(sizeof(vmid_bitmap) * 8U)) { + while (id < CONFIG_MAX_VM_NUM) { if (!bitmap_test_and_set_lock(id, &vmid_bitmap)) { - return id; + break; } id = ffz64(vmid_bitmap); } - return INVALID_VM_ID; + id = (id >= CONFIG_MAX_VM_NUM) ? INVALID_VM_ID : id; + return id; } static inline void free_vm_id(const struct acrn_vm *vm)