GPU-DRM-Savage: Use memdup_user() rather than duplicating
authorMarkus Elfring <elfring@users.sourceforge.net>
Thu, 18 Aug 2016 16:12:03 +0000 (18:12 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 19 Aug 2016 08:58:55 +0000 (10:58 +0200)
Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/021efa32-c259-e799-a80e-630972291815@users.sourceforge.net
drivers/gpu/drm/savage/savage_state.c

index c01ad0aeaa5806dd034910eff873d48a149fdbc5..3dc0d8ff95ec6d1e047d1e27d0587cd5d1cc7199 100644 (file)
@@ -1001,15 +1001,9 @@ int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_
                cmdbuf->cmd_addr = kcmd_addr;
        }
        if (cmdbuf->vb_size) {
-               kvb_addr = kmalloc(cmdbuf->vb_size, GFP_KERNEL);
-               if (kvb_addr == NULL) {
-                       ret = -ENOMEM;
-                       goto done;
-               }
-
-               if (copy_from_user(kvb_addr, cmdbuf->vb_addr,
-                                      cmdbuf->vb_size)) {
-                       ret = -EFAULT;
+               kvb_addr = memdup_user(cmdbuf->vb_addr, cmdbuf->vb_size);
+               if (IS_ERR(kvb_addr)) {
+                       ret = PTR_ERR(kvb_addr);
                        goto done;
                }
                cmdbuf->vb_addr = kvb_addr;