* [PATCH] KVM: x86: Redundant variable assignments can be merged
@ 2022-11-30 11:55 liujing
2022-11-30 15:43 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: liujing @ 2022-11-30 11:55 UTC (permalink / raw)
To: seanjc; +Cc: pbonzini, tglx, mingo, bp, dave.hansen, linux-kernel, liujing
When reading kvm code, find the 'r' variable declaration
and then assign the value in kvm_vm_ioctl_get_irqchip and
kvm_vm_ioctl_set_irqchip function, It can be combined into one sentence.
Signed-off-by: liujing <liujing@cmss.chinamobile.com>
---
arch/x86/kvm/x86.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2835bd796639..4be353d5c09d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6002,9 +6002,8 @@ 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;
+ int r = 0;
- r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
memcpy(&chip->chip.pic, &pic->pics[0],
@@ -6027,9 +6026,8 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
{
struct kvm_pic *pic = kvm->arch.vpic;
- int r;
+ int r = 0;
- r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
spin_lock(&pic->lock);
--
2.18.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: x86: Redundant variable assignments can be merged
2022-11-30 11:55 [PATCH] KVM: x86: Redundant variable assignments can be merged liujing
@ 2022-11-30 15:43 ` Sean Christopherson
0 siblings, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2022-11-30 15:43 UTC (permalink / raw)
To: liujing; +Cc: pbonzini, tglx, mingo, bp, dave.hansen, linux-kernel
State what the patch does, not what can be done. And "redundant" isn't the right
word to describe this.
On Wed, Nov 30, 2022, liujing wrote:
> When reading kvm code, find the 'r' variable declaration
> and then assign the value in kvm_vm_ioctl_get_irqchip and
> kvm_vm_ioctl_set_irqchip function, It can be combined into one sentence.
Why though? I actually kinda like the existing code.
That said, what about removing the variable entirely? That'd also avoid the
unnecessary call to kvm_pic_update_irq() in set's error path.
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d2ad383da998..898fce19430a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6011,9 +6011,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],
@@ -6027,18 +6025,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);
@@ -6056,11 +6051,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)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] KVM: x86: Redundant variable assignments can be merged
@ 2022-11-30 12:59 liujing
0 siblings, 0 replies; 3+ messages in thread
From: liujing @ 2022-11-30 12:59 UTC (permalink / raw)
To: pbonzini; +Cc: mingo, dave.hansen, kvm, linux-kernel, liujing
When reading kvm code, find the 'r' variable declaration
and then assign the value in kvm_vm_ioctl_get_irqchip and
kvm_vm_ioctl_set_irqchip function, It can be combined into one sentence.
Signed-off-by: liujing <liujing@cmss.chinamobile.com>
---
arch/x86/kvm/x86.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2835bd796639..4be353d5c09d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6002,9 +6002,8 @@ 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;
+ int r = 0;
- r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
memcpy(&chip->chip.pic, &pic->pics[0],
@@ -6027,9 +6026,8 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
{
struct kvm_pic *pic = kvm->arch.vpic;
- int r;
+ int r = 0;
- r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
spin_lock(&pic->lock);
--
2.18.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-30 15:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-30 11:55 [PATCH] KVM: x86: Redundant variable assignments can be merged liujing
2022-11-30 15:43 ` Sean Christopherson
-- strict thread matches above, loose matches on Subject: below --
2022-11-30 12:59 liujing
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox