public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user
@ 2012-11-02  2:43 Fengguang Wu
  2012-11-09 13:06 ` Alex Williamson
  0 siblings, 1 reply; 2+ messages in thread
From: Fengguang Wu @ 2012-11-02  2:43 UTC (permalink / raw)
  To: Alex Williamson; +Cc: linux-kernel, Julia Lawall

Generated by: coccinelle/api/memdup_user.cocci

Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
---

 drivers/vfio/pci/vfio_pci.c |   13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

--- linux.orig/drivers/vfio/pci/vfio_pci.c	2012-10-23 18:21:57.118168335 +0800
+++ linux/drivers/vfio/pci/vfio_pci.c	2012-11-02 10:39:36.101317628 +0800
@@ -327,15 +327,10 @@ static long vfio_pci_ioctl(void *device_
 			    hdr.count > vfio_pci_get_irq_count(vdev, hdr.index))
 				return -EINVAL;
 
-			data = kmalloc(hdr.count * size, GFP_KERNEL);
-			if (!data)
-				return -ENOMEM;
-
-			if (copy_from_user(data, (void __user *)(arg + minsz),
-					   hdr.count * size)) {
-				kfree(data);
-				return -EFAULT;
-			}
+			data = memdup_user((void __user *)(arg + minsz),
+					   hdr.count * size);
+			if (IS_ERR(data))
+				return PTR_ERR(data);
 		}
 
 		mutex_lock(&vdev->igate);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user
  2012-11-02  2:43 [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user Fengguang Wu
@ 2012-11-09 13:06 ` Alex Williamson
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2012-11-09 13:06 UTC (permalink / raw)
  To: Fengguang Wu; +Cc: linux-kernel, Julia Lawall

On Fri, 2012-11-02 at 10:43 +0800, Fengguang Wu wrote:
> Generated by: coccinelle/api/memdup_user.cocci
> 
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
> Reported-by: Fengguang Wu <fengguang.wu@intel.com>
> ---
> 
>  drivers/vfio/pci/vfio_pci.c |   13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> --- linux.orig/drivers/vfio/pci/vfio_pci.c	2012-10-23 18:21:57.118168335 +0800
> +++ linux/drivers/vfio/pci/vfio_pci.c	2012-11-02 10:39:36.101317628 +0800
> @@ -327,15 +327,10 @@ static long vfio_pci_ioctl(void *device_
>  			    hdr.count > vfio_pci_get_irq_count(vdev, hdr.index))
>  				return -EINVAL;
>  
> -			data = kmalloc(hdr.count * size, GFP_KERNEL);
> -			if (!data)
> -				return -ENOMEM;
> -
> -			if (copy_from_user(data, (void __user *)(arg + minsz),
> -					   hdr.count * size)) {
> -				kfree(data);
> -				return -EFAULT;
> -			}
> +			data = memdup_user((void __user *)(arg + minsz),
> +					   hdr.count * size);
> +			if (IS_ERR(data))
> +				return PTR_ERR(data);
>  		}
>  
>  		mutex_lock(&vdev->igate);


Thanks for the patch.  Looks reasonable to me.  I'll add it to my next
tree for 3.8.  Thanks,

Alex


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-09 13:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-02  2:43 [PATCH] vfio: simplify kmalloc+copy_from_user to memdup_user Fengguang Wu
2012-11-09 13:06 ` Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox