aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorJulia Lawall <julia@diku.dk>2010-05-15 17:17:40 -0400
committerDave Airlie <airlied@redhat.com>2010-05-18 01:55:55 -0400
commitf405a1ab2bf316b1969fc5355891e5dff4e1a54c (patch)
tree30bf6908ec23fa0695b111c672d7f3abc6f4ceaf /drivers/gpu
parentca117d6df95a8f809d37d74c2d715ec3c8c3a4ed (diff)
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: Julia Lawall <julia@diku.dk> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_grctx.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_bios.c3
2 files changed, 3 insertions, 6 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_grctx.c b/drivers/gpu/drm/nouveau/nouveau_grctx.c
index 32f0e495464c..f731c5f60536 100644
--- a/drivers/gpu/drm/nouveau/nouveau_grctx.c
+++ b/drivers/gpu/drm/nouveau/nouveau_grctx.c
@@ -68,13 +68,12 @@ nouveau_grctx_prog_load(struct drm_device *dev)
68 return ret; 68 return ret;
69 } 69 }
70 70
71 pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL); 71 pgraph->ctxprog = kmemdup(fw->data, fw->size, GFP_KERNEL);
72 if (!pgraph->ctxprog) { 72 if (!pgraph->ctxprog) {
73 NV_ERROR(dev, "OOM copying ctxprog\n"); 73 NV_ERROR(dev, "OOM copying ctxprog\n");
74 release_firmware(fw); 74 release_firmware(fw);
75 return -ENOMEM; 75 return -ENOMEM;
76 } 76 }
77 memcpy(pgraph->ctxprog, fw->data, fw->size);
78 77
79 cp = pgraph->ctxprog; 78 cp = pgraph->ctxprog;
80 if (le32_to_cpu(cp->signature) != 0x5043564e || 79 if (le32_to_cpu(cp->signature) != 0x5043564e ||
@@ -97,14 +96,13 @@ nouveau_grctx_prog_load(struct drm_device *dev)
97 return ret; 96 return ret;
98 } 97 }
99 98
100 pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL); 99 pgraph->ctxvals = kmemdup(fw->data, fw->size, GFP_KERNEL);
101 if (!pgraph->ctxvals) { 100 if (!pgraph->ctxvals) {
102 NV_ERROR(dev, "OOM copying ctxvals\n"); 101 NV_ERROR(dev, "OOM copying ctxvals\n");
103 release_firmware(fw); 102 release_firmware(fw);
104 nouveau_grctx_fini(dev); 103 nouveau_grctx_fini(dev);
105 return -ENOMEM; 104 return -ENOMEM;
106 } 105 }
107 memcpy(pgraph->ctxvals, fw->data, fw->size);
108 106
109 cv = (void *)pgraph->ctxvals; 107 cv = (void *)pgraph->ctxvals;
110 if (le32_to_cpu(cv->signature) != 0x5643564e || 108 if (le32_to_cpu(cv->signature) != 0x5643564e ||
diff --git a/drivers/gpu/drm/radeon/radeon_bios.c b/drivers/gpu/drm/radeon/radeon_bios.c
index 8ad71f701316..fbba938f8048 100644
--- a/drivers/gpu/drm/radeon/radeon_bios.c
+++ b/drivers/gpu/drm/radeon/radeon_bios.c
@@ -85,12 +85,11 @@ static bool radeon_read_bios(struct radeon_device *rdev)
85 pci_unmap_rom(rdev->pdev, bios); 85 pci_unmap_rom(rdev->pdev, bios);
86 return false; 86 return false;
87 } 87 }
88 rdev->bios = kmalloc(size, GFP_KERNEL); 88 rdev->bios = kmemdup(bios, size, GFP_KERNEL);
89 if (rdev->bios == NULL) { 89 if (rdev->bios == NULL) {
90 pci_unmap_rom(rdev->pdev, bios); 90 pci_unmap_rom(rdev->pdev, bios);
91 return false; 91 return false;
92 } 92 }
93 memcpy(rdev->bios, bios, size);
94 pci_unmap_rom(rdev->pdev, bios); 93 pci_unmap_rom(rdev->pdev, bios);
95 return true; 94 return true;
96} 95}