arch/loongarch/kvm/exit.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
The default branch has already handled all undefined cases,
so the final return statement is redundant.
Signed-off-by: cuitao <cuitao@kylinos.cn>
---
arch/loongarch/kvm/exit.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 2ce41f93b2a4..e501867740b1 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -778,9 +778,7 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu)
return 0;
default:
return KVM_HCALL_INVALID_CODE;
- };
-
- return KVM_HCALL_INVALID_CODE;
+ }
};
/*
--
2.48.1
On 2025/9/4 下午12:26, cuitao wrote:
> The default branch has already handled all undefined cases,
> so the final return statement is redundant.
>
> Signed-off-by: cuitao <cuitao@kylinos.cn>
> ---
> arch/loongarch/kvm/exit.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
> index 2ce41f93b2a4..e501867740b1 100644
> --- a/arch/loongarch/kvm/exit.c
> +++ b/arch/loongarch/kvm/exit.c
> @@ -778,9 +778,7 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu)
> return 0;
> default:
> return KVM_HCALL_INVALID_CODE;
> - };
> -
> - return KVM_HCALL_INVALID_CODE;
> + }
> };
>
> /*
In my opinion, there is only one case, no need to use switch case,
the ";" at the end can be removed, the code can be like this:
static long kvm_save_notify(struct kvm_vcpu *vcpu)
{
unsigned long id, data;
id = kvm_read_reg(vcpu, LOONGARCH_GPR_A1);
data = kvm_read_reg(vcpu, LOONGARCH_GPR_A2);
if (id == BIT(KVM_FEATURE_STEAL_TIME)) {
if (data & ~(KVM_STEAL_PHYS_MASK | KVM_STEAL_PHYS_VALID))
return KVM_HCALL_INVALID_PARAMETER;
vcpu->arch.st.guest_addr = data;
if (!(data & KVM_STEAL_PHYS_VALID))
return 0;
vcpu->arch.st.last_steal = current->sched_info.run_delay;
kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);
return 0;
}
return KVM_HCALL_INVALID_CODE;
}
The following is the diff:
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c
index 2ce41f93b2a4..0c18761539fc 100644
--- a/arch/loongarch/kvm/exit.c
+++ b/arch/loongarch/kvm/exit.c
@@ -764,8 +764,7 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu)
id = kvm_read_reg(vcpu, LOONGARCH_GPR_A1);
data = kvm_read_reg(vcpu, LOONGARCH_GPR_A2);
- switch (id) {
- case BIT(KVM_FEATURE_STEAL_TIME):
+ if (id == BIT(KVM_FEATURE_STEAL_TIME)) {
if (data & ~(KVM_STEAL_PHYS_MASK | KVM_STEAL_PHYS_VALID))
return KVM_HCALL_INVALID_PARAMETER;
@@ -776,12 +775,10 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu)
vcpu->arch.st.last_steal = current->sched_info.run_delay;
kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);
return 0;
- default:
- return KVM_HCALL_INVALID_CODE;
- };
+ }
return KVM_HCALL_INVALID_CODE;
-};
+}
/*
* kvm_handle_lsx_disabled() - Guest used LSX while disabled in root.
Thanks,
Tiezhu
Thanks for the review. My initial idea was to remove the switch-case structure. However, after checking the case value KVM_FEATURE_STEAL_TIME, I found there are 13 parallel definitions—and it is unclear when this part of the development will be completed later. Therefore, I temporarily retained the switch-case structure. Now, I have updated the patch according to your suggestion: - Replaced `switch` with `if` since there is only one case. - Removed the redundant semicolon after the block. Please see the updated patch below. Thanks, Tiezhu
On Thu, Sep 4, 2025 at 4:14 PM cuitao <cuitao@kylinos.cn> wrote: > > Thanks for the review. > > My initial idea was to remove the switch-case structure. > However, after checking the case value KVM_FEATURE_STEAL_TIME, > I found there are 13 parallel definitions—and it is unclear when > this part of the development will be completed later. Therefore, > I temporarily retained the switch-case structure. > > Now, I have updated the patch according to your suggestion: > - Replaced `switch` with `if` since there is only one case. > - Removed the redundant semicolon after the block. > > Please see the updated patch below. It has been applied, don't make useless effort. https://github.com/chenhuacai/linux/commit/f5d35375a6546bcc5d0993e3a48cdbc3a7217544 Huacai > > Thanks, > Tiezhu
On 2025/9/4 下午4:20, Huacai Chen wrote: > On Thu, Sep 4, 2025 at 4:14 PM cuitao <cuitao@kylinos.cn> wrote: >> >> Thanks for the review. >> >> My initial idea was to remove the switch-case structure. >> However, after checking the case value KVM_FEATURE_STEAL_TIME, >> I found there are 13 parallel definitions—and it is unclear when >> this part of the development will be completed later. Therefore, >> I temporarily retained the switch-case structure. >> >> Now, I have updated the patch according to your suggestion: >> - Replaced `switch` with `if` since there is only one case. >> - Removed the redundant semicolon after the block. >> >> Please see the updated patch below. > It has been applied, don't make useless effort. > https://github.com/chenhuacai/linux/commit/f5d35375a6546bcc5d0993e3a48cdbc3a7217544 I think that it is unnecessary to replace `switch` with `if` here:) One thing is that the change is big for such thing, and also there may be new case condition in future, just maybe. Regards Bibo Mao > > Huacai > >> >> Thanks, >> Tiezhu
On 2025/9/4 下午12:26, cuitao wrote: > The default branch has already handled all undefined cases, > so the final return statement is redundant. > > Signed-off-by: cuitao <cuitao@kylinos.cn> > --- > arch/loongarch/kvm/exit.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c > index 2ce41f93b2a4..e501867740b1 100644 > --- a/arch/loongarch/kvm/exit.c > +++ b/arch/loongarch/kvm/exit.c > @@ -778,9 +778,7 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu) > return 0; > default: > return KVM_HCALL_INVALID_CODE; > - }; > - > - return KVM_HCALL_INVALID_CODE; > + } > }; > > /* > Reviewed-by: Bibo Mao <maobibo@loongson.cn>
On Thu, Sep 4, 2025 at 2:17 PM Bibo Mao <maobibo@loongson.cn> wrote: > > > > On 2025/9/4 下午12:26, cuitao wrote: > > The default branch has already handled all undefined cases, > > so the final return statement is redundant. > > > > Signed-off-by: cuitao <cuitao@kylinos.cn> > > --- > > arch/loongarch/kvm/exit.c | 4 +--- > > 1 file changed, 1 insertion(+), 3 deletions(-) > > > > diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c > > index 2ce41f93b2a4..e501867740b1 100644 > > --- a/arch/loongarch/kvm/exit.c > > +++ b/arch/loongarch/kvm/exit.c > > @@ -778,9 +778,7 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu) > > return 0; > > default: > > return KVM_HCALL_INVALID_CODE; > > - }; > > - > > - return KVM_HCALL_INVALID_CODE; > > + } > > }; > > > > /* > > > Reviewed-by: Bibo Mao <maobibo@loongson.cn> Applied, thanks. Huacai > >
© 2016 - 2026 Red Hat, Inc.