diff mbox series

[5/6] KVM: x86: check kvm_pit outside kvm_vm_ioctl_reinject()

Message ID 1575710723-32094-6-git-send-email-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series remove unnecessary return val of kvm pit | expand

Commit Message

Miaohe Lin Dec. 7, 2019, 9:25 a.m. UTC
From: Miaohe Lin <linmiaohe@huawei.com>

check kvm_pit outside kvm_vm_ioctl_reinject() to keep codestyle consistent
with other kvm_pit func and prepare for futher cleanups.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/x86.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini Jan. 15, 2020, 5:53 p.m. UTC | #1
On 07/12/19 10:25, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> check kvm_pit outside kvm_vm_ioctl_reinject() to keep codestyle consistent
> with other kvm_pit func and prepare for futher cleanups.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  arch/x86/kvm/x86.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2d4e3a2dfec6..00b5d4ace383 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4662,9 +4662,6 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm,
>  {
>  	struct kvm_pit *pit = kvm->arch.vpit;
>  
> -	if (!pit)
> -		return -ENXIO;
> -
>  	/* pit->pit_state.lock was overloaded to prevent userspace from getting
>  	 * an inconsistent state after running multiple KVM_REINJECT_CONTROL
>  	 * ioctls in parallel.  Use a separate lock if that ioctl isn't rare.
> @@ -5029,6 +5026,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
>  		r =  -EFAULT;
>  		if (copy_from_user(&control, argp, sizeof(control)))
>  			goto out;
> +		r = -ENXIO;
> +		if (!kvm->arch.vpit)
> +			goto out;
>  		r = kvm_vm_ioctl_reinject(kvm, &control);
>  		break;
>  	}
> 

Applied this one, I don't think the others are a useful improvement.

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2d4e3a2dfec6..00b5d4ace383 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4662,9 +4662,6 @@  static int kvm_vm_ioctl_reinject(struct kvm *kvm,
 {
 	struct kvm_pit *pit = kvm->arch.vpit;
 
-	if (!pit)
-		return -ENXIO;
-
 	/* pit->pit_state.lock was overloaded to prevent userspace from getting
 	 * an inconsistent state after running multiple KVM_REINJECT_CONTROL
 	 * ioctls in parallel.  Use a separate lock if that ioctl isn't rare.
@@ -5029,6 +5026,9 @@  long kvm_arch_vm_ioctl(struct file *filp,
 		r =  -EFAULT;
 		if (copy_from_user(&control, argp, sizeof(control)))
 			goto out;
+		r = -ENXIO;
+		if (!kvm->arch.vpit)
+			goto out;
 		r = kvm_vm_ioctl_reinject(kvm, &control);
 		break;
 	}