Skip to content

Commit 6e37ec8

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Use ERR_PTR_USR() to return -EFAULT as a __user pointer
Use ERR_PTR_USR() when returning -EFAULT from kvm_get_attr_addr(), sparse complains about implicitly casting the kernel pointer from ERR_PTR() into a __user pointer. >> arch/x86/kvm/x86.c:4342:31: sparse: sparse: incorrect type in return expression (different address spaces) @@ expected void [noderef] __user * @@ got void * @@ arch/x86/kvm/x86.c:4342:31: sparse: expected void [noderef] __user * arch/x86/kvm/x86.c:4342:31: sparse: got void * >> arch/x86/kvm/x86.c:4342:31: sparse: sparse: incorrect type in return expression (different address spaces) @@ expected void [noderef] __user * @@ got void * @@ arch/x86/kvm/x86.c:4342:31: sparse: expected void [noderef] __user * arch/x86/kvm/x86.c:4342:31: sparse: got void * No functional change intended. Fixes: 56f289a ("KVM: x86: Add a helper to retrieve userspace address from kvm_device_attr") Reported-by: kernel test robot <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e3bcfda commit 6e37ec8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/x86/kvm/x86.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
u64 __read_mostly kvm_mce_cap_supported = MCG_CTL_P | MCG_SER_P;
9191
EXPORT_SYMBOL_GPL(kvm_mce_cap_supported);
9292

93+
#define ERR_PTR_USR(e) ((void __user *)ERR_PTR(e))
94+
9395
#define emul_to_vcpu(ctxt) \
9496
((struct kvm_vcpu *)(ctxt)->vcpu)
9597

@@ -4340,7 +4342,7 @@ static inline void __user *kvm_get_attr_addr(struct kvm_device_attr *attr)
43404342
void __user *uaddr = (void __user*)(unsigned long)attr->addr;
43414343

43424344
if ((u64)(unsigned long)uaddr != attr->addr)
4343-
return ERR_PTR(-EFAULT);
4345+
return ERR_PTR_USR(-EFAULT);
43444346
return uaddr;
43454347
}
43464348

@@ -11684,8 +11686,6 @@ void kvm_arch_sync_events(struct kvm *kvm)
1168411686
kvm_free_pit(kvm);
1168511687
}
1168611688

11687-
#define ERR_PTR_USR(e) ((void __user *)ERR_PTR(e))
11688-
1168911689
/**
1169011690
* __x86_set_memory_region: Setup KVM internal memory slot
1169111691
*

0 commit comments

Comments
 (0)