Merge tag 'drm-qemu-20160921' of git://git.kraxel.org/linux into drm-next
[linux-2.6-block.git] / drivers / gpu / drm / virtio / virtgpu_ioctl.c
index e0613a9c283325a1a3979a599f9fb0022f488390..818478b4c4f0aec5baf5fe737e9dfd9a954afeff 100644 (file)
@@ -158,15 +158,10 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
        if (ret)
                goto out_free;
 
-       buf = kmalloc(exbuf->size, GFP_KERNEL);
-       if (!buf) {
-               ret = -ENOMEM;
-               goto out_unresv;
-       }
-       if (copy_from_user(buf, (void __user *)(uintptr_t)exbuf->command,
-                          exbuf->size)) {
-               kfree(buf);
-               ret = -EFAULT;
+       buf = memdup_user((void __user *)(uintptr_t)exbuf->command,
+                         exbuf->size);
+       if (IS_ERR(buf)) {
+               ret = PTR_ERR(buf);
                goto out_unresv;
        }
        virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,