drm/vmwgfx: Use kmemdup instead of kmalloc and memcpy
authorShyam Saini <mayhs11saini@gmail.com>
Thu, 19 Jan 2017 21:45:34 +0000 (13:45 -0800)
committerSinclair Yeh <syeh@vmware.com>
Fri, 27 Jan 2017 05:26:17 +0000 (21:26 -0800)
When some other buffer is immediately copied into allocated region.
Replace calls to kmalloc followed by a memcpy with a direct
call to kmemdup.

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Reviewed-by: Sinclair Yeh <syeh@vmare.com>
drivers/gpu/drm/vmwgfx/vmwgfx_mob.c

index b6126a5f12695074a5f22a7d81ae31f4b9af9f83..941bcfd131ff7a169472b0b92c62cf7a40e01bd9 100644 (file)
@@ -319,18 +319,17 @@ int vmw_otables_setup(struct vmw_private *dev_priv)
        int ret;
 
        if (dev_priv->has_dx) {
-               *otables = kmalloc(sizeof(dx_tables), GFP_KERNEL);
+               *otables = kmemdup(dx_tables, sizeof(dx_tables), GFP_KERNEL);
                if (*otables == NULL)
                        return -ENOMEM;
 
-               memcpy(*otables, dx_tables, sizeof(dx_tables));
                dev_priv->otable_batch.num_otables = ARRAY_SIZE(dx_tables);
        } else {
-               *otables = kmalloc(sizeof(pre_dx_tables), GFP_KERNEL);
+               *otables = kmemdup(pre_dx_tables, sizeof(pre_dx_tables),
+                                  GFP_KERNEL);
                if (*otables == NULL)
                        return -ENOMEM;
 
-               memcpy(*otables, pre_dx_tables, sizeof(pre_dx_tables));
                dev_priv->otable_batch.num_otables = ARRAY_SIZE(pre_dx_tables);
        }