[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221201014237.5764-1-liujing@cmss.chinamobile.com>
Date: Wed, 30 Nov 2022 20:42:37 -0500
From: liujing <liujing@...s.chinamobile.com>
To: pbonzini@...hat.com
Cc: tglx@...utronix.de, mingo@...hat.com, dave.hansen@...ux.intel.com,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
liujing <liujing@...s.chinamobile.com>
Subject: [PATCH] KVM: x86: Optimize your code to avoid unnecessary calls
In the kvm_vm_ioctl_get_irqchip function, we can removethe
definition of the r variable instead of return 0 in the end.
In the kvm_vm_ioctl_set_irqchip function, also use return 0 instead,
return -EINVAL to avoid calling kvm_pic_update_irq again.
Signed-off-by: liujing <liujing@...s.chinamobile.com>
---
arch/x86/kvm/x86.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2835bd796639..8e94f3d730ee 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6002,9 +6002,7 @@ static unsigned long kvm_vm_ioctl_get_nr_mmu_pages(struct kvm *kvm)
static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
{
struct kvm_pic *pic = kvm->arch.vpic;
- int r;
- r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
memcpy(&chip->chip.pic, &pic->pics[0],
@@ -6018,18 +6016,15 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
kvm_get_ioapic(kvm, &chip->chip.ioapic);
break;
default:
- r = -EINVAL;
- break;
+ return -EINVAL;
}
- return r;
+ return 0;
}
static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
{
struct kvm_pic *pic = kvm->arch.vpic;
- int r;
-
- r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
spin_lock(&pic->lock);
@@ -6047,11 +6042,10 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
kvm_set_ioapic(kvm, &chip->chip.ioapic);
break;
default:
- r = -EINVAL;
- break;
+ return -EINVAL;
}
kvm_pic_update_irq(pic);
- return r;
+ return 0;
}
static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)
--
2.18.2
Powered by blists - more mailing lists