From patchwork Thu May 26 14:01:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rakib Mullick X-Patchwork-Id: 825192 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4RIMVX1025075 for ; Fri, 27 May 2011 18:22:52 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8623F9E80F for ; Fri, 27 May 2011 11:22:31 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wy0-f177.google.com (mail-wy0-f177.google.com [74.125.82.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 295649E764 for ; Thu, 26 May 2011 07:01:28 -0700 (PDT) Received: by wyb28 with SMTP id 28so653446wyb.36 for ; Thu, 26 May 2011 07:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:from:to:cc:content-type:date:message-id :mime-version:x-mailer:content-transfer-encoding; bh=/23LCg5NU3ObsDucqwfAqjoknMPbohpIlg3XUVuk05A=; b=fwdlh2DOclOoHftCYfd4mXmq70btCy9AvwkSK7jEaIfZ/7POCmhJA8NZcExkZRiFjt 3c7m1mgLbg+LAgjpNcecQ6obtyeREkbdz3L5bPyYceI9WGujcTSd+vTGMjHY0InzCaD8 uk0IC/NeqWzntyivzXGhPpWuUfdkI6GKBSt5E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=SEQZblr0gIGNLY7FNOcFFlEVmK9TI4pHiSeLEJ9c4KbKa59zC+t4d9qlNRWFfSyfOx rTXvWbEzwYFwJ4Y8qL4onEoRHRYALzOg37mBfPm0Tg+xMYeq1GimzK1Bq3eZ30aoh8pz Jsy7k4ny/BcvZvTpsNeczggMMD9sBCXy9I1OY= Received: by 10.227.199.68 with SMTP id er4mr878863wbb.47.1306418487918; Thu, 26 May 2011 07:01:27 -0700 (PDT) Received: from [10.54.185.35] ([119.30.38.51]) by mx.google.com with ESMTPS id b10sm491886wbh.60.2011.05.26.07.01.16 (version=SSLv3 cipher=OTHER); Thu, 26 May 2011 07:01:26 -0700 (PDT) Subject: [PATCH v1] drivers: Use kzalloc instead of 'kmalloc+memset', where possible From: Rakib Mullick To: linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Thu, 26 May 2011 20:01:05 +0600 Message-ID: <1306418465.2786.6.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 (2.32.1-1.fc14) X-Mailman-Approved-At: Fri, 27 May 2011 11:22:23 -0700 Cc: joe@perches.com, akpm@linux-foundation.org, Jeff Garzik X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 27 May 2011 18:22:52 +0000 (UTC) A previous patch was sent to address this issue at, https://lkml.org/lkml/2011/5/23/305. Joe Perches suggest that, its best to use kcalloc for array allocation instead of kzalloc. This version addresses this issue. Changes since V0: Use kcalloc instead of kzalloc for array allocation. Signed-off-by: Rakib Mullick diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c index 1c4b3aa..168b78f 100644 --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c @@ -1638,13 +1638,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_out; } - memset(hsdev, 0, sizeof(*hsdev)); /* Ioremap SATA registers */ base = of_iomap(ofdev->dev.of_node, 0); diff --git a/drivers/gpu/drm/drm_scatter.c b/drivers/gpu/drm/drm_scatter.c index d15e09b..7525e03 100644 --- a/drivers/gpu/drm/drm_scatter.c +++ b/drivers/gpu/drm/drm_scatter.c @@ -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) { diff --git a/drivers/gpu/drm/radeon/radeon_mem.c b/drivers/gpu/drm/radeon/radeon_mem.c index ed95155..988548e 100644 --- a/drivers/gpu/drm/radeon/radeon_mem.c +++ b/drivers/gpu/drm/radeon/radeon_mem.c @@ -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; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c b/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c index f1a52f9..07ce02d 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c @@ -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; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index 5408b1b..bfe1bcc 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c @@ -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; diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c index be8d4cb..370de0b 100644 --- a/drivers/gpu/vga/vgaarb.c +++ b/drivers/gpu/vga/vgaarb.c @@ -1094,10 +1094,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;