lkml.org 
[lkml]   [2024]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH for-6.8 1/5] KVM: LoongArch: Fix input value checking of _kvm_get_cpucfg
    Date
    From: WANG Xuerui <git@xen0n.name>

    The range check for the CPUCFG ID is wrong (should have been a ||
    instead of &&), and pointless, because the default case a few lines
    below already serves to deny all unhandled cases.

    Furthermore, the juggling of the temp return value is unnecessary,
    because it is semantically equivalent and more readable to just
    return at every switch case's end. This is done too to avoid potential
    bugs in the future related to the unwanted complexity.

    Fixes: db1ecca22edf ("LoongArch: KVM: Add LSX (128bit SIMD) support")
    Signed-off-by: WANG Xuerui <git@xen0n.name>
    ---
    arch/loongarch/kvm/vcpu.c | 11 ++---------
    1 file changed, 2 insertions(+), 9 deletions(-)

    diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
    index 27701991886d..c4a592623da6 100644
    --- a/arch/loongarch/kvm/vcpu.c
    +++ b/arch/loongarch/kvm/vcpu.c
    @@ -300,11 +300,6 @@ static int _kvm_setcsr(struct kvm_vcpu *vcpu, unsigned int id, u64 val)

    static int _kvm_get_cpucfg(int id, u64 *v)
    {
    - int ret = 0;
    -
    - if (id < 0 && id >= KVM_MAX_CPUCFG_REGS)
    - return -EINVAL;
    -
    switch (id) {
    case 2:
    /* Return CPUCFG2 features which have been supported by KVM */
    @@ -324,12 +319,10 @@ static int _kvm_get_cpucfg(int id, u64 *v)
    if (cpu_has_lasx)
    *v |= CPUCFG2_LASX;

    - break;
    + return 0;
    default:
    - ret = -EINVAL;
    - break;
    + return -EINVAL;
    }
    - return ret;
    }

    static int kvm_check_cpucfg(int id, u64 val)
    --
    2.43.0

    \
     
     \ /
      Last update: 2024-05-27 15:02    [W:5.873 / U:0.112 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site