Skip to contentSkip to conversation

virtio-gpu: Use memdup_user() rather than duplicating its implementation

PATCH Applied SF Markus Elfring 2 participants 3 messages Aug 18, 2016 – Aug 19, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-gpu: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Thu, 18 Aug 2016 22:35:14 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -9
index c046903..512e7cd 100644
@@ -152,15 +152,10 @@ static int virtio_gpu_execbuffer(struct drm_device *dev,
 	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,
Signature · 1 line
2.9.3
#1 lore raw
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 18 Aug 2016 22:35:14 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Applied to drm-misc.
-Daniel

Quoted 35 lines
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -9
index c046903..512e7cd 100644
@@ -152,15 +152,10 @@ static int virtio_gpu_execbuffer(struct drm_device *dev,
 	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,
Signature · 6 lines
2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#2 lore raw
In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 18 Aug 2016 22:35:14 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Applied to drm-misc.
-Daniel

Quoted 35 lines
---
 drivers/gpu/drm/virtio/virtgpu_ioctl.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +4 -9
index c046903..512e7cd 100644
@@ -152,15 +152,10 @@ static int virtio_gpu_execbuffer(struct drm_device *dev,
 	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,
Signature · 6 lines
2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch