From patchwork Fri Jan 11 09:27:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 1965251 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id E1800DF2A2 for ; Fri, 11 Jan 2013 09:27:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753330Ab3AKJ1H (ORCPT ); Fri, 11 Jan 2013 04:27:07 -0500 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]:41245 "EHLO tama500.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752237Ab3AKJ1G (ORCPT ); Fri, 11 Jan 2013 04:27:06 -0500 Received: from mfs6.rdh.ecl.ntt.co.jp (mfs6.rdh.ecl.ntt.co.jp [129.60.39.149]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id r0B9R4cd013544; Fri, 11 Jan 2013 18:27:04 +0900 Received: from mfs6.rdh.ecl.ntt.co.jp (localhost.localdomain [127.0.0.1]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 1787DE0194; Fri, 11 Jan 2013 18:27:04 +0900 (JST) Received: from imail2.m.ecl.ntt.co.jp (imail2.m.ecl.ntt.co.jp [129.60.5.247]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 0BF63E018E; Fri, 11 Jan 2013 18:27:04 +0900 (JST) Received: from yshpad ([129.60.241.180]) by imail2.m.ecl.ntt.co.jp (8.13.8/8.13.8) with SMTP id r0B9R3sl026802; Fri, 11 Jan 2013 18:27:04 +0900 Date: Fri, 11 Jan 2013 18:27:43 +0900 From: Takuya Yoshikawa To: mtosatti@redhat.com, gleb@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH 3/4] KVM: set_memory_region: Remove unnecessary variable memslot Message-Id: <20130111182743.8cc9b80e.yoshikawa_takuya_b1@lab.ntt.co.jp> In-Reply-To: <20130111182518.6c5975d9.yoshikawa_takuya_b1@lab.ntt.co.jp> References: <20130111182518.6c5975d9.yoshikawa_takuya_b1@lab.ntt.co.jp> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org One such variable, slot, is enough for holding a pointer temporarily. We also remove another local variable named slot, which is limited in a block, since it is confusing to have the same name in this function. Signed-off-by: Takuya Yoshikawa --- virt/kvm/kvm_main.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f6c8cdc..8cb4e71 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -728,7 +728,7 @@ int __kvm_set_memory_region(struct kvm *kvm, int r; gfn_t base_gfn; unsigned long npages; - struct kvm_memory_slot *memslot, *slot; + struct kvm_memory_slot *slot; struct kvm_memory_slot old, new; struct kvm_memslots *slots = NULL, *old_memslots; @@ -754,7 +754,7 @@ int __kvm_set_memory_region(struct kvm *kvm, if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr) goto out; - memslot = id_to_memslot(kvm->memslots, mem->slot); + slot = id_to_memslot(kvm->memslots, mem->slot); base_gfn = mem->guest_phys_addr >> PAGE_SHIFT; npages = mem->memory_size >> PAGE_SHIFT; @@ -765,7 +765,7 @@ int __kvm_set_memory_region(struct kvm *kvm, if (!npages) mem->flags &= ~KVM_MEM_LOG_DIRTY_PAGES; - new = old = *memslot; + new = old = *slot; new.id = mem->slot; new.base_gfn = base_gfn; @@ -786,7 +786,8 @@ int __kvm_set_memory_region(struct kvm *kvm, /* Check for overlaps */ r = -EEXIST; kvm_for_each_memslot(slot, kvm->memslots) { - if (slot->id >= KVM_USER_MEM_SLOTS || slot == memslot) + if ((slot->id >= KVM_USER_MEM_SLOTS) || + (slot->id == mem->slot)) continue; if (!((base_gfn + npages <= slot->base_gfn) || (base_gfn >= slot->base_gfn + slot->npages))) @@ -823,8 +824,6 @@ int __kvm_set_memory_region(struct kvm *kvm, } if (!npages || base_gfn != old.base_gfn) { - struct kvm_memory_slot *slot; - r = -ENOMEM; slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), GFP_KERNEL);