vfio: simplify kmalloc+copy_from_user to memdup_user
authorFengguang Wu <fengguang.wu@intel.com>
Fri, 7 Dec 2012 20:43:49 +0000 (13:43 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 7 Dec 2012 20:43:49 +0000 (13:43 -0700)
Generated by: coccinelle/api/memdup_user.cocci

Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci.c

index 6c119944bbb6e8c03f7e15424494b17d4fbdd5db..a4dc21b9cb06d1c9d1eeeba3618eb33755b43b0f 100644 (file)
@@ -327,15 +327,10 @@ static long vfio_pci_ioctl(void *device_data,
                            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);
This page took 0.027857 seconds and 5 git commands to generate.