Commit f405a1ab authored by Julia Lawall's avatar Julia Lawall Committed by Dave Airlie

drivers/gpu/drm: Use kmemdup

Use kmemdup when some other buffer is immediately copied into the
allocated region.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression from,to,size,flag;
statement S;
@@

-  to = \(kmalloc\|kzalloc\)(size,flag);
+  to = kmemdup(from,size,flag);
   if (to==NULL || ...) S
-  memcpy(to, from, size);
// </smpl>
Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent ca117d6d
...@@ -68,13 +68,12 @@ nouveau_grctx_prog_load(struct drm_device *dev) ...@@ -68,13 +68,12 @@ nouveau_grctx_prog_load(struct drm_device *dev)
return ret; return ret;
} }
pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL); pgraph->ctxprog = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!pgraph->ctxprog) { if (!pgraph->ctxprog) {
NV_ERROR(dev, "OOM copying ctxprog\n"); NV_ERROR(dev, "OOM copying ctxprog\n");
release_firmware(fw); release_firmware(fw);
return -ENOMEM; return -ENOMEM;
} }
memcpy(pgraph->ctxprog, fw->data, fw->size);
cp = pgraph->ctxprog; cp = pgraph->ctxprog;
if (le32_to_cpu(cp->signature) != 0x5043564e || if (le32_to_cpu(cp->signature) != 0x5043564e ||
...@@ -97,14 +96,13 @@ nouveau_grctx_prog_load(struct drm_device *dev) ...@@ -97,14 +96,13 @@ nouveau_grctx_prog_load(struct drm_device *dev)
return ret; return ret;
} }
pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL); pgraph->ctxvals = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!pgraph->ctxvals) { if (!pgraph->ctxvals) {
NV_ERROR(dev, "OOM copying ctxvals\n"); NV_ERROR(dev, "OOM copying ctxvals\n");
release_firmware(fw); release_firmware(fw);
nouveau_grctx_fini(dev); nouveau_grctx_fini(dev);
return -ENOMEM; return -ENOMEM;
} }
memcpy(pgraph->ctxvals, fw->data, fw->size);
cv = (void *)pgraph->ctxvals; cv = (void *)pgraph->ctxvals;
if (le32_to_cpu(cv->signature) != 0x5643564e || if (le32_to_cpu(cv->signature) != 0x5643564e ||
......
...@@ -85,12 +85,11 @@ static bool radeon_read_bios(struct radeon_device *rdev) ...@@ -85,12 +85,11 @@ static bool radeon_read_bios(struct radeon_device *rdev)
pci_unmap_rom(rdev->pdev, bios); pci_unmap_rom(rdev->pdev, bios);
return false; return false;
} }
rdev->bios = kmalloc(size, GFP_KERNEL); rdev->bios = kmemdup(bios, size, GFP_KERNEL);
if (rdev->bios == NULL) { if (rdev->bios == NULL) {
pci_unmap_rom(rdev->pdev, bios); pci_unmap_rom(rdev->pdev, bios);
return false; return false;
} }
memcpy(rdev->bios, bios, size);
pci_unmap_rom(rdev->pdev, bios); pci_unmap_rom(rdev->pdev, bios);
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment