Skip to content

Commit

Permalink
kvm: svm: fix unsigned compare less than zero comparison
Browse files Browse the repository at this point in the history
vm_data->avic_vm_id is a u32, so the check for a error
return (less than zero) such as -EAGAIN from
avic_get_next_vm_id currently has no effect whatsoever.
Fix this by using a temporary int for the comparison
and assign vm_data->avic_vm_id to this. I used an explicit
u32 cast in the assignment to show why vm_data->avic_vm_id
cannot be used in the assign/compare steps.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Colin Ian King authored and Paolo Bonzini committed Sep 20, 2016
1 parent 095cf55 commit adad0d0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions arch/x86/kvm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1412,17 +1412,18 @@ static void avic_vm_destroy(struct kvm *kvm)
static int avic_vm_init(struct kvm *kvm)
{
unsigned long flags;
int err = -ENOMEM;
int vm_id, err = -ENOMEM;
struct kvm_arch *vm_data = &kvm->arch;
struct page *p_page;
struct page *l_page;

if (!avic)
return 0;

vm_data->avic_vm_id = avic_get_next_vm_id();
if (vm_data->avic_vm_id < 0)
return vm_data->avic_vm_id;
vm_id = avic_get_next_vm_id();
if (vm_id < 0)
return vm_id;
vm_data->avic_vm_id = (u32)vm_id;

/* Allocating physical APIC ID table (4KB) */
p_page = alloc_page(GFP_KERNEL);
Expand Down

0 comments on commit adad0d0

Please sign in to comment.