drivers: use kzalloc/kcalloc instead of 'kmalloc+memset', where possible
authorRakib Mullick <rakib.mullick@gmail.com>
Tue, 26 Jul 2011 00:12:56 +0000 (17:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 26 Jul 2011 03:57:13 +0000 (20:57 -0700)
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>
drivers/ata/sata_dwc_460ex.c
drivers/gpu/drm/drm_scatter.c
drivers/gpu/drm/radeon/radeon_mem.c
drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
drivers/gpu/vga/vgaarb.c

index b02c4ffa4db0ff123ea8497030f674a3707d4f1d..0a9a774a7e1e9f54c9b2188b251b2a5105c800ea 100644 (file)
@@ -1642,13 +1642,12 @@ static int sata_dwc_probe(struct platform_device *ofdev)
        const struct ata_port_info *ppi[] = { &pi, NULL };
 
        /* Allocate DWC SATA device */
-       hsdev = kmalloc(sizeof(*hsdev), GFP_KERNEL);
+       hsdev = kzalloc(sizeof(*hsdev), GFP_KERNEL);
        if (hsdev == NULL) {
                dev_err(&ofdev->dev, "kmalloc failed for hsdev\n");
                err = -ENOMEM;
                goto error;
        }
-       memset(hsdev, 0, sizeof(*hsdev));
 
        /* Ioremap SATA registers */
        base = of_iomap(ofdev->dev.of_node, 0);
index d15e09b0ae0bf8c322712d5e3101f7dc8d53eb6a..7525e0311e5903ca1d80a94e6ed292de9c4817af 100644 (file)
@@ -83,30 +83,26 @@ int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
        if (dev->sg)
                return -EINVAL;
 
-       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+       entry = kzalloc(sizeof(*entry), GFP_KERNEL);
        if (!entry)
                return -ENOMEM;
 
-       memset(entry, 0, sizeof(*entry));
        pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
        DRM_DEBUG("size=%ld pages=%ld\n", request->size, pages);
 
        entry->pages = pages;
-       entry->pagelist = kmalloc(pages * sizeof(*entry->pagelist), GFP_KERNEL);
+       entry->pagelist = kcalloc(pages, sizeof(*entry->pagelist), GFP_KERNEL);
        if (!entry->pagelist) {
                kfree(entry);
                return -ENOMEM;
        }
 
-       memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));
-
-       entry->busaddr = kmalloc(pages * sizeof(*entry->busaddr), GFP_KERNEL);
+       entry->busaddr = kcalloc(pages, sizeof(*entry->busaddr), GFP_KERNEL);
        if (!entry->busaddr) {
                kfree(entry->pagelist);
                kfree(entry);
                return -ENOMEM;
        }
-       memset((void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr));
 
        entry->virtual = drm_vmalloc_dma(pages << PAGE_SHIFT);
        if (!entry->virtual) {
index ed95155c4b1d64136f99fada3e577d0d967fdffa..988548efea92acdcace34b6d91c25707650e8da9 100644 (file)
@@ -139,7 +139,7 @@ static int init_heap(struct mem_block **heap, int start, int size)
        if (!blocks)
                return -ENOMEM;
 
-       *heap = kmalloc(sizeof(**heap), GFP_KERNEL);
+       *heap = kzalloc(sizeof(**heap), GFP_KERNEL);
        if (!*heap) {
                kfree(blocks);
                return -ENOMEM;
@@ -150,7 +150,6 @@ static int init_heap(struct mem_block **heap, int start, int size)
        blocks->file_priv = NULL;
        blocks->next = blocks->prev = *heap;
 
-       memset(*heap, 0, sizeof(**heap));
        (*heap)->file_priv = (struct drm_file *) - 1;
        (*heap)->next = (*heap)->prev = blocks;
        return 0;
index f1a52f9e72988da041c77f19b1035f5b3f160592..07ce02da78a44546106d4dd6cbfbffd287059187 100644 (file)
@@ -585,11 +585,10 @@ int vmw_overlay_init(struct vmw_private *dev_priv)
                return -ENOSYS;
        }
 
-       overlay = kmalloc(sizeof(*overlay), GFP_KERNEL);
+       overlay = kzalloc(sizeof(*overlay), GFP_KERNEL);
        if (!overlay)
                return -ENOMEM;
 
-       memset(overlay, 0, sizeof(*overlay));
        mutex_init(&overlay->mutex);
        for (i = 0; i < VMW_MAX_NUM_STREAMS; i++) {
                overlay->stream[i].buf = NULL;
index 5408b1b7996f054dee95b9ed5aac4e9d63ee99a1..bfe1bcce7f8a3c32ed5e4d2071001f28607a6cbb 100644 (file)
@@ -612,11 +612,9 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
            srf->sizes[0].height == 64 &&
            srf->format == SVGA3D_A8R8G8B8) {
 
-               srf->snooper.image = kmalloc(64 * 64 * 4, GFP_KERNEL);
-               /* clear the image */
-               if (srf->snooper.image) {
-                       memset(srf->snooper.image, 0x00, 64 * 64 * 4);
-               } else {
+               /* allocate image area and clear it */
+               srf->snooper.image = kzalloc(64 * 64 * 4, GFP_KERNEL);
+               if (!srf->snooper.image) {
                        DRM_ERROR("Failed to allocate cursor_image\n");
                        ret = -ENOMEM;
                        goto out_err1;
index 8a1021f2e319e1f1918fadd25550bf9e1a7c4b84..c72f1c0b5e637951a450b21378f2edfeb8e92725 100644 (file)
@@ -1171,10 +1171,9 @@ static int vga_arb_open(struct inode *inode, struct file *file)
 
        pr_debug("%s\n", __func__);
 
-       priv = kmalloc(sizeof(struct vga_arb_private), GFP_KERNEL);
+       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
        if (priv == NULL)
                return -ENOMEM;
-       memset(priv, 0, sizeof(*priv));
        spin_lock_init(&priv->lock);
        file->private_data = priv;