diff options
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r-- | virt/kvm/kvm_main.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e6cfd4344d28..1cd693a76a51 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -714,8 +714,7 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
714 | int r; | 714 | int r; |
715 | gfn_t base_gfn; | 715 | gfn_t base_gfn; |
716 | unsigned long npages; | 716 | unsigned long npages; |
717 | unsigned long i; | 717 | struct kvm_memory_slot *memslot, *slot; |
718 | struct kvm_memory_slot *memslot; | ||
719 | struct kvm_memory_slot old, new; | 718 | struct kvm_memory_slot old, new; |
720 | struct kvm_memslots *slots, *old_memslots; | 719 | struct kvm_memslots *slots, *old_memslots; |
721 | 720 | ||
@@ -766,13 +765,11 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
766 | 765 | ||
767 | /* Check for overlaps */ | 766 | /* Check for overlaps */ |
768 | r = -EEXIST; | 767 | r = -EEXIST; |
769 | for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { | 768 | kvm_for_each_memslot(slot, kvm->memslots) { |
770 | struct kvm_memory_slot *s = &kvm->memslots->memslots[i]; | 769 | if (slot->id >= KVM_MEMORY_SLOTS || slot == memslot) |
771 | |||
772 | if (s == memslot || !s->npages) | ||
773 | continue; | 770 | continue; |
774 | if (!((base_gfn + npages <= s->base_gfn) || | 771 | if (!((base_gfn + npages <= slot->base_gfn) || |
775 | (base_gfn >= s->base_gfn + s->npages))) | 772 | (base_gfn >= slot->base_gfn + slot->npages))) |
776 | goto out_free; | 773 | goto out_free; |
777 | } | 774 | } |
778 | 775 | ||