From: WANG Xuerui <git@xxxxxxxxxx> The return value of _kvm_get_cpucfg is meant to be checked, but this was not done, so bad CPUCFG IDs wrongly fall back to the default case and 0 is returned. Check the return value to fix the UAPI behavior. While at it, also remove the redundant range check, because _kvm_get_cpucfg already rejects all unrecognized input CPUCFG IDs. It was also wrong and no-op, in the same way as the former identical check in _kvm_get_cpucfg. Fixes: db1ecca22edf ("LoongArch: KVM: Add LSX (128bit SIMD) support") Signed-off-by: WANG Xuerui <git@xxxxxxxxxx> --- arch/loongarch/kvm/vcpu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c index c4a592623da6..cc2332b056ba 100644 --- a/arch/loongarch/kvm/vcpu.c +++ b/arch/loongarch/kvm/vcpu.c @@ -328,12 +328,10 @@ static int _kvm_get_cpucfg(int id, u64 *v) static int kvm_check_cpucfg(int id, u64 val) { u64 mask; - int ret = 0; - - if (id < 0 && id >= KVM_MAX_CPUCFG_REGS) - return -EINVAL; + int ret; - if (_kvm_get_cpucfg(id, &mask)) + ret = _kvm_get_cpucfg(id, &mask); + if (ret) return ret; switch (id) { -- 2.43.0