lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <462e346b-424d-263d-19a8-766d578d9781@loongson.cn>
Date: Thu, 4 Sep 2025 14:34:30 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: cuitao <cuitao@...inos.cn>, zhaotianrui@...ngson.cn, maobibo@...ngson.cn,
 chenhuacai@...nel.org, loongarch@...ts.linux.dev
Cc: kernel@...0n.name, kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] LoongArch: KVM: remove unused returns.

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@...inos.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ