diff mbox

kvm: vfio: silence GCC warning

Message ID 1389313726.2039.9.camel@x220 (mailing list archive)
State New, archived
Headers show

Commit Message

Paul Bolle Jan. 10, 2014, 12:28 a.m. UTC
Building vfio.o triggers a GCC warning (when building for 32 bits x86):
    arch/x86/kvm/../../../virt/kvm/vfio.c: In function 'kvm_vfio_set_group':
    arch/x86/kvm/../../../virt/kvm/vfio.c:104:22: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      void __user *argp = (void __user *)arg;
                          ^

Silence this warning by casting arg to unsigned long.

argp's current type, "void __user *", is always casted to "int32_t
__user *". So its type might as well be changed to "int32_t __user *".

Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
---
Compile tested on both 32 and 64 bits x86. I've no KVM capable hardware
that is already running v3.13-rc* at hand. Besides, I wouldn't know how
to test the codepaths I'm changing here.

 virt/kvm/vfio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Alex Williamson Jan. 10, 2014, 5:59 p.m. UTC | #1
On Fri, 2014-01-10 at 01:28 +0100, Paul Bolle wrote:
> Building vfio.o triggers a GCC warning (when building for 32 bits x86):
>     arch/x86/kvm/../../../virt/kvm/vfio.c: In function 'kvm_vfio_set_group':
>     arch/x86/kvm/../../../virt/kvm/vfio.c:104:22: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       void __user *argp = (void __user *)arg;
>                           ^
> 
> Silence this warning by casting arg to unsigned long.
> 
> argp's current type, "void __user *", is always casted to "int32_t
> __user *". So its type might as well be changed to "int32_t __user *".
> 
> Signed-off-by: Paul Bolle <pebolle@tiscali.nl>

Acked-by: Alex Williamson <alex.williamson@redhat.com>

> ---
> Compile tested on both 32 and 64 bits x86. I've no KVM capable hardware
> that is already running v3.13-rc* at hand. Besides, I wouldn't know how
> to test the codepaths I'm changing here.
> 
>  virt/kvm/vfio.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> index ca4260e..b4f9507 100644
> --- a/virt/kvm/vfio.c
> +++ b/virt/kvm/vfio.c
> @@ -101,14 +101,14 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
>  	struct kvm_vfio *kv = dev->private;
>  	struct vfio_group *vfio_group;
>  	struct kvm_vfio_group *kvg;
> -	void __user *argp = (void __user *)arg;
> +	int32_t __user *argp = (int32_t __user *)(unsigned long)arg;
>  	struct fd f;
>  	int32_t fd;
>  	int ret;
>  
>  	switch (attr) {
>  	case KVM_DEV_VFIO_GROUP_ADD:
> -		if (get_user(fd, (int32_t __user *)argp))
> +		if (get_user(fd, argp))
>  			return -EFAULT;
>  
>  		f = fdget(fd);
> @@ -148,7 +148,7 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
>  		return 0;
>  
>  	case KVM_DEV_VFIO_GROUP_DEL:
> -		if (get_user(fd, (int32_t __user *)argp))
> +		if (get_user(fd, argp))
>  			return -EFAULT;
>  
>  		f = fdget(fd);



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Paolo Bonzini Jan. 15, 2014, 11:02 a.m. UTC | #2
Il 10/01/2014 01:28, Paul Bolle ha scritto:
> Building vfio.o triggers a GCC warning (when building for 32 bits x86):
>     arch/x86/kvm/../../../virt/kvm/vfio.c: In function 'kvm_vfio_set_group':
>     arch/x86/kvm/../../../virt/kvm/vfio.c:104:22: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>       void __user *argp = (void __user *)arg;
>                           ^
> 
> Silence this warning by casting arg to unsigned long.
> 
> argp's current type, "void __user *", is always casted to "int32_t
> __user *". So its type might as well be changed to "int32_t __user *".
> 
> Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
> ---
> Compile tested on both 32 and 64 bits x86. I've no KVM capable hardware
> that is already running v3.13-rc* at hand. Besides, I wouldn't know how
> to test the codepaths I'm changing here.
> 
>  virt/kvm/vfio.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> index ca4260e..b4f9507 100644
> --- a/virt/kvm/vfio.c
> +++ b/virt/kvm/vfio.c
> @@ -101,14 +101,14 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
>  	struct kvm_vfio *kv = dev->private;
>  	struct vfio_group *vfio_group;
>  	struct kvm_vfio_group *kvg;
> -	void __user *argp = (void __user *)arg;
> +	int32_t __user *argp = (int32_t __user *)(unsigned long)arg;
>  	struct fd f;
>  	int32_t fd;
>  	int ret;
>  
>  	switch (attr) {
>  	case KVM_DEV_VFIO_GROUP_ADD:
> -		if (get_user(fd, (int32_t __user *)argp))
> +		if (get_user(fd, argp))
>  			return -EFAULT;
>  
>  		f = fdget(fd);
> @@ -148,7 +148,7 @@ static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
>  		return 0;
>  
>  	case KVM_DEV_VFIO_GROUP_DEL:
> -		if (get_user(fd, (int32_t __user *)argp))
> +		if (get_user(fd, argp))
>  			return -EFAULT;
>  
>  		f = fdget(fd);
> 

Applied to kvm/queue, thanks.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index ca4260e..b4f9507 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -101,14 +101,14 @@  static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
 	struct kvm_vfio *kv = dev->private;
 	struct vfio_group *vfio_group;
 	struct kvm_vfio_group *kvg;
-	void __user *argp = (void __user *)arg;
+	int32_t __user *argp = (int32_t __user *)(unsigned long)arg;
 	struct fd f;
 	int32_t fd;
 	int ret;
 
 	switch (attr) {
 	case KVM_DEV_VFIO_GROUP_ADD:
-		if (get_user(fd, (int32_t __user *)argp))
+		if (get_user(fd, argp))
 			return -EFAULT;
 
 		f = fdget(fd);
@@ -148,7 +148,7 @@  static int kvm_vfio_set_group(struct kvm_device *dev, long attr, u64 arg)
 		return 0;
 
 	case KVM_DEV_VFIO_GROUP_DEL:
-		if (get_user(fd, (int32_t __user *)argp))
+		if (get_user(fd, argp))
 			return -EFAULT;
 
 		f = fdget(fd);