From patchwork Wed Feb 14 16:33:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 201033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1341345dyb; Wed, 14 Feb 2024 08:39:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW5BLix9ZGg+b+OV5qXsjX++l95GMGBlvg8N9N2WohAiXSvhunL4aeiyMdKpoSJk5e5h3iNimcgruVgPnX+vrWYwcl9VQ== X-Google-Smtp-Source: AGHT+IEMG+TlXJz6NfAE7/RNU1yx4lkTuUvDwLxu5nWUJ8C0BX70hXtFmWogR5qGhfOpT7dXl7q4 X-Received: by 2002:a05:6a00:1803:b0:6e1:738:93cf with SMTP id y3-20020a056a00180300b006e1073893cfmr3541160pfa.30.1707928770972; Wed, 14 Feb 2024 08:39:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707928770; cv=pass; d=google.com; s=arc-20160816; b=MjOUPUFm5nBKNol0fi7C0zTtXwpVwL9hAA1RE8x6ByaAepTY9L6X2b5Ur+gGiEKvbj q+5aH17gM768SpABLcq9i392zkxo15bx9OHbYvKnSotI8dMeFqb4J7DZvhFhqm8kR91n JoddRf4myybj2Vh7PJRtqpIZkMqAm7384i2D7MkPHzpQ9N572qrYLIeb/RH0FReAyemf Xs7jLZkJ/oaqugWnDpyvMXkGIM5ChnrXN7xf1e3pKNImJ0H/Dzt0uDtodk7fXYeEBtnY 8N1SpcqX7kH+VtQlxzzMhl1pIGor31mioen4PW7dXkODI/oBLvxKhu4GjTvo3CA/BcXP HzDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bfiqB3+pwN35nisRVs+YFHtHnge1kJcbRHJbqJ+9U+o=; fh=03WhE3iote43Jd5DBTjR9a63oT4B0TrVt7RO7A7KOOA=; b=lxs02Jkwj03HO21vbaBhyaRGcKXe0yDq4pMasynzFp3VKgjnbwvJI9tPAz2nGXm0yj /oJ7rBTKRdKMIcILijY6OAFrs8LVU4kfC3tiJHVe3UJdMWidGA34wNjsxTj9kOjSk+l2 QQqxP+4sJhEPxq/6wuEkBwSWTKs1b3CntpMNFbHZRXMKZ8v78Q1ujDpMgDrmnCp8LI04 KnQkfiV5eWGeEG9U56QfHOaFzZkP24Ajn8rQZxF99wUWNFHqZEZW3aaxTVxO5beZDo5G r9fLe5twF3hwnDfY0b8zw/OytPh5H4gggAnQtNeRACN7TPezS0X0SbKibdXtg6VTIo2y gMcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=ZNU0AkXX; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXDL3ytJK1uFb0JD51s15nFYS5ZElQS1UHhmaOFOeixI9amQXk63cE2fXshG/3XeQRpb7iHptljLsTlioeOyFQqTDzdBA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 126-20020a630084000000b005dc48e561adsi3798741pga.20.2024.02.14.08.39.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 08:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=ZNU0AkXX; arc=pass (i=1 spf=pass spfdomain=xen0n.name dkim=pass dkdomain=xen0n.name); spf=pass (google.com: domain of linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65555-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 86A96281891 for ; Wed, 14 Feb 2024 16:37:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C2DC65198; Wed, 14 Feb 2024 16:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b="ZNU0AkXX" Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1735E5FF16; Wed, 14 Feb 2024 16:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.28.160.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; cv=none; b=q1EwQBKVY6r96i/t+W7IY4pUAQ0+UhauC2/73kdOrT8bfztsLGyT2yCdLe6iEXpj+hbKgi3LHY/P+ByIYzuPlnazlbnCLUI3txPbKzEfAA9jKdMjfbrCjZETUuBDSuRGwgpNqt0KMwhZBoEKn1cq7SSvXFye6uzQSl5M2YDFVyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707928446; c=relaxed/simple; bh=qUTm7/R3ovfw0MXxK4QrZKdILlZUuBNM9kI6bR5Fxzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZSUWscURgajYnaoqIkekL4T6/dNX4eVpgmSPJymoGU3jyWsTLydIx2JJnpDaI7Kz7uyiJob3p/OX2iX8z9SNhN3qh7X71hRZKhTJHyIETeUsyeCJmZxhDA1ebOHkAJdEpRaXHV6q1ZhFKSm6oelQgmg3IUYTDF+EtHUP3T8Cw5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name; spf=pass smtp.mailfrom=xen0n.name; dkim=pass (1024-bit key) header.d=xen0n.name header.i=@xen0n.name header.b=ZNU0AkXX; arc=none smtp.client-ip=115.28.160.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1707928441; bh=qUTm7/R3ovfw0MXxK4QrZKdILlZUuBNM9kI6bR5Fxzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNU0AkXX04CwM3rMQCCubKT7skrrj0VQW66Is5+V1MQyNxnY5LDUUe1L4voIFJ1vH NoEbvYoF9cKwr6ofnBvYlg2hkbMBUnEsHOxaDuSohruYvUH45ZJarDyHMElfK6rli4 yTIfRvmdTBaROi9uTRmpVLZnSkX14DLrLQfnty54= Received: from ld50.lan (unknown [IPv6:240e:388:8d00:6500:42e8:c06f:a0dc:12f8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 90E38601A7; Thu, 15 Feb 2024 00:34:01 +0800 (CST) From: WANG Xuerui To: Paolo Bonzini , Huacai Chen Cc: Tianrui Zhao , Bibo Mao , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH for-6.8 v2 1/4] KVM: LoongArch: Fix input value checking of _kvm_get_cpucfg Date: Thu, 15 Feb 2024 00:33:54 +0800 Message-ID: <20240214163358.2913090-2-kernel@xen0n.name> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214163358.2913090-1-kernel@xen0n.name> References: <20240214163358.2913090-1-kernel@xen0n.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790893118622261659 X-GMAIL-MSGID: 1790893118622261659 From: WANG Xuerui 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 --- 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)