Skip to content

Commit f35119d

Browse files
rmullicktorvalds
authored andcommitted
drivers: use kzalloc/kcalloc instead of 'kmalloc+memset', where possible
Signed-off-by: Rakib Mullick <rakib.mullick@gmail.com> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: David Airlie <airlied@linux.ie> Cc: Tejun Heo <tj@kernel.org> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f1c93e4 commit f35119d

6 files changed

Lines changed: 10 additions & 20 deletions

File tree

‎drivers/ata/sata_dwc_460ex.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,13 +1642,12 @@ static int sata_dwc_probe(struct platform_device *ofdev)
16421642
const struct ata_port_info *ppi[] = { &pi, NULL };
16431643

16441644
/* Allocate DWC SATA device */
1645-
hsdev = kmalloc(sizeof(*hsdev), GFP_KERNEL);
1645+
hsdev = kzalloc(sizeof(*hsdev), GFP_KERNEL);
16461646
if (hsdev == NULL) {
16471647
dev_err(&ofdev->dev, "kmalloc failed for hsdev\n");
16481648
err = -ENOMEM;
16491649
goto error;
16501650
}
1651-
memset(hsdev, 0, sizeof(*hsdev));
16521651

16531652
/* Ioremap SATA registers */
16541653
base = of_iomap(ofdev->dev.of_node, 0);

‎drivers/gpu/drm/drm_scatter.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,26 @@ int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
8383
if (dev->sg)
8484
return -EINVAL;
8585

86-
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
86+
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
8787
if (!entry)
8888
return -ENOMEM;
8989

90-
memset(entry, 0, sizeof(*entry));
9190
pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
9291
DRM_DEBUG("size=%ld pages=%ld\n", request->size, pages);
9392

9493
entry->pages = pages;
95-
entry->pagelist = kmalloc(pages * sizeof(*entry->pagelist), GFP_KERNEL);
94+
entry->pagelist = kcalloc(pages, sizeof(*entry->pagelist), GFP_KERNEL);
9695
if (!entry->pagelist) {
9796
kfree(entry);
9897
return -ENOMEM;
9998
}
10099

101-
memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));
102-
103-
entry->busaddr = kmalloc(pages * sizeof(*entry->busaddr), GFP_KERNEL);
100+
entry->busaddr = kcalloc(pages, sizeof(*entry->busaddr), GFP_KERNEL);
104101
if (!entry->busaddr) {
105102
kfree(entry->pagelist);
106103
kfree(entry);
107104
return -ENOMEM;
108105
}
109-
memset((void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr));
110106

111107
entry->virtual = drm_vmalloc_dma(pages << PAGE_SHIFT);
112108
if (!entry->virtual) {

‎drivers/gpu/drm/radeon/radeon_mem.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int init_heap(struct mem_block **heap, int start, int size)
139139
if (!blocks)
140140
return -ENOMEM;
141141

142-
*heap = kmalloc(sizeof(**heap), GFP_KERNEL);
142+
*heap = kzalloc(sizeof(**heap), GFP_KERNEL);
143143
if (!*heap) {
144144
kfree(blocks);
145145
return -ENOMEM;
@@ -150,7 +150,6 @@ static int init_heap(struct mem_block **heap, int start, int size)
150150
blocks->file_priv = NULL;
151151
blocks->next = blocks->prev = *heap;
152152

153-
memset(*heap, 0, sizeof(**heap));
154153
(*heap)->file_priv = (struct drm_file *) - 1;
155154
(*heap)->next = (*heap)->prev = blocks;
156155
return 0;

‎drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,10 @@ int vmw_overlay_init(struct vmw_private *dev_priv)
585585
return -ENOSYS;
586586
}
587587

588-
overlay = kmalloc(sizeof(*overlay), GFP_KERNEL);
588+
overlay = kzalloc(sizeof(*overlay), GFP_KERNEL);
589589
if (!overlay)
590590
return -ENOMEM;
591591

592-
memset(overlay, 0, sizeof(*overlay));
593592
mutex_init(&overlay->mutex);
594593
for (i = 0; i < VMW_MAX_NUM_STREAMS; i++) {
595594
overlay->stream[i].buf = NULL;

‎drivers/gpu/drm/vmwgfx/vmwgfx_resource.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,9 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
612612
srf->sizes[0].height == 64 &&
613613
srf->format == SVGA3D_A8R8G8B8) {
614614

615-
srf->snooper.image = kmalloc(64 * 64 * 4, GFP_KERNEL);
616-
/* clear the image */
617-
if (srf->snooper.image) {
618-
memset(srf->snooper.image, 0x00, 64 * 64 * 4);
619-
} else {
615+
/* allocate image area and clear it */
616+
srf->snooper.image = kzalloc(64 * 64 * 4, GFP_KERNEL);
617+
if (!srf->snooper.image) {
620618
DRM_ERROR("Failed to allocate cursor_image\n");
621619
ret = -ENOMEM;
622620
goto out_err1;

‎drivers/gpu/vga/vgaarb.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,9 @@ static int vga_arb_open(struct inode *inode, struct file *file)
11711171

11721172
pr_debug("%s\n", __func__);
11731173

1174-
priv = kmalloc(sizeof(struct vga_arb_private), GFP_KERNEL);
1174+
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
11751175
if (priv == NULL)
11761176
return -ENOMEM;
1177-
memset(priv, 0, sizeof(*priv));
11781177
spin_lock_init(&priv->lock);
11791178
file->private_data = priv;
11801179

0 commit comments

Comments
 (0)