In case certain allocations fail, vmx_create_vcpu may return 0 as error
instead of a negative value encoded via ERR_PTR. This causes a NULL
pointer dereferencing later on in kvm_vm_ioctl_vcpu_create.
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
                goto free_vcpu;
 
        vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
+       err = -ENOMEM;
        if (!vmx->guest_msrs) {
-               err = -ENOMEM;
                goto uninit_vcpu;
        }
 
        if (err)
                goto free_vmcs;
        if (vm_need_virtualize_apic_accesses(kvm))
-               if (alloc_apic_access_page(kvm) != 0)
+               err = alloc_apic_access_page(kvm);
+               if (err)
                        goto free_vmcs;
 
        if (enable_ept) {