From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A111DC35646 for ; Fri, 21 Feb 2020 14:04:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B20B20679 for ; Fri, 21 Feb 2020 14:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728835AbgBUOEM (ORCPT ); Fri, 21 Feb 2020 09:04:12 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:52632 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728228AbgBUOEL (ORCPT ); Fri, 21 Feb 2020 09:04:11 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 48B6B38CB97C8456B5DC; Fri, 21 Feb 2020 22:03:59 +0800 (CST) Received: from huawei.com (10.175.105.18) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Fri, 21 Feb 2020 22:03:52 +0800 From: linmiaohe To: , , , , , , , , , , CC: , , , Subject: [PATCH] KVM: X86: eliminate some meaningless code Date: Fri, 21 Feb 2020 22:05:26 +0800 Message-ID: <1582293926-23388-1-git-send-email-linmiaohe@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.105.18] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin When kvm_vcpu_ioctl_get_cpuid2() fails, we set cpuid->nent to the value of vcpu->arch.cpuid_nent. But this is in vain as cpuid->nent is not copied to userspace by copy_to_user() from call site. Get rid of this meaningless assignment and further cleanup the var r and out jump label. On the other hand, when kvm_vcpu_ioctl_get_cpuid2() succeeds, we do not change the content of struct cpuid. We can avoid copy_to_user() from call site as struct cpuid remain unchanged. Signed-off-by: Miaohe Lin --- arch/x86/kvm/cpuid.c | 14 ++++---------- arch/x86/kvm/x86.c | 6 ------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index b1c469446b07..b83cedc63328 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -265,20 +265,14 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 __user *entries) { - int r; - - r = -E2BIG; if (cpuid->nent < vcpu->arch.cpuid_nent) - goto out; - r = -EFAULT; + return -E2BIG; + if (copy_to_user(entries, &vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2))) - goto out; - return 0; + return -EFAULT; -out: - cpuid->nent = vcpu->arch.cpuid_nent; - return r; + return 0; } static __always_inline void cpuid_mask(u32 *word, int wordnum) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fbabb2f06273..683c54e7be36 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4295,12 +4295,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, goto out; r = kvm_vcpu_ioctl_get_cpuid2(vcpu, &cpuid, cpuid_arg->entries); - if (r) - goto out; - r = -EFAULT; - if (copy_to_user(cpuid_arg, &cpuid, sizeof(cpuid))) - goto out; - r = 0; break; } case KVM_GET_MSRS: { -- 2.19.1