From patchwork Fri Oct 11 13:36:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pekon gupta X-Patchwork-Id: 3024421 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D9BB8BF924 for ; Fri, 11 Oct 2013 13:39:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D36820253 for ; Fri, 11 Oct 2013 13:39:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A67CF2024C for ; Fri, 11 Oct 2013 13:39:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757896Ab3JKNjp (ORCPT ); Fri, 11 Oct 2013 09:39:45 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:45498 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755769Ab3JKNjo (ORCPT ); Fri, 11 Oct 2013 09:39:44 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id r9BDbTdn025788; Fri, 11 Oct 2013 08:37:37 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r9BDbTDU008914; Fri, 11 Oct 2013 08:37:29 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.2.342.3; Fri, 11 Oct 2013 08:37:29 -0500 Received: from psplinux063.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id r9BDapQW023475; Fri, 11 Oct 2013 08:37:24 -0500 From: Pekon Gupta To: , , , , CC: , , , , , , , , , , , , Pekon Gupta Subject: [PATCH v8 6/6] mtd: nand: omap: updated devm_xx for all resource allocation and free calls Date: Fri, 11 Oct 2013 19:06:43 +0530 Message-ID: <1381498603-15715-7-git-send-email-pekon@ti.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1381498603-15715-1-git-send-email-pekon@ti.com> References: <1381498603-15715-1-git-send-email-pekon@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "Managed Device Resource" or devm_xx calls takes care of automatic freeing of the resource in case of: - failure during driver probe - failure during resource allocation - detaching or unloading of driver module (rmmod) Reference: Documentation/driver-model/devres.txt Though OMAP NAND driver handles freeing of resource allocation in most of the cases, but using devm_xx provides more clean and effortless approach to handle all such cases. Signed-off-by: Pekon Gupta Reviewed-by: Felipe Balbi --- drivers/mtd/nand/omap2.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index a783dae..0f2b0d1 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c @@ -1658,7 +1658,8 @@ static int omap_nand_probe(struct platform_device *pdev) return -ENODEV; } - info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL); + info = devm_kzalloc(&pdev->dev, sizeof(struct omap_nand_info), + GFP_KERNEL); if (!info) return -ENOMEM; @@ -1690,13 +1691,14 @@ static int omap_nand_probe(struct platform_device *pdev) info->phys_base = res->start; info->mem_size = resource_size(res); - if (!request_mem_region(info->phys_base, info->mem_size, - pdev->dev.driver->name)) { + if (!devm_request_mem_region(&pdev->dev, info->phys_base, + info->mem_size, pdev->dev.driver->name)) { err = -EBUSY; goto out_free_info; } - info->nand.IO_ADDR_R = ioremap(info->phys_base, info->mem_size); + info->nand.IO_ADDR_R = devm_ioremap(&pdev->dev, info->phys_base, + info->mem_size); if (!info->nand.IO_ADDR_R) { err = -ENOMEM; goto out_release_mem_region; @@ -1799,8 +1801,9 @@ static int omap_nand_probe(struct platform_device *pdev) err = -ENODEV; goto out_release_mem_region; } - err = request_irq(info->gpmc_irq_fifo, omap_nand_irq, - IRQF_SHARED, "gpmc-nand-fifo", info); + err = devm_request_irq(&pdev->dev, info->gpmc_irq_fifo, + omap_nand_irq, IRQF_SHARED, + "gpmc-nand-fifo", info); if (err) { dev_err(&pdev->dev, "requesting irq(%d) error:%d", info->gpmc_irq_fifo, err); @@ -1814,8 +1817,9 @@ static int omap_nand_probe(struct platform_device *pdev) err = -ENODEV; goto out_release_mem_region; } - err = request_irq(info->gpmc_irq_count, omap_nand_irq, - IRQF_SHARED, "gpmc-nand-count", info); + err = devm_request_irq(&pdev->dev, info->gpmc_irq_count, + omap_nand_irq, IRQF_SHARED, + "gpmc-nand-count", info); if (err) { dev_err(&pdev->dev, "requesting irq(%d) error:%d", info->gpmc_irq_count, err); @@ -2031,10 +2035,10 @@ out_release_mem_region: if (info->dma) dma_release_channel(info->dma); if (info->gpmc_irq_count > 0) - free_irq(info->gpmc_irq_count, info); + devm_free_irq(&pdev->dev, info->gpmc_irq_count, info); if (info->gpmc_irq_fifo > 0) - free_irq(info->gpmc_irq_fifo, info); - release_mem_region(info->phys_base, info->mem_size); + devm_free_irq(&pdev->dev, info->gpmc_irq_fifo, info); + devm_release_mem_region(&pdev->dev, info->phys_base, info->mem_size); out_free_info: #ifdef CONFIG_MTD_NAND_ECC_BCH if (info->nand.ecc.priv) { @@ -2042,7 +2046,7 @@ out_free_info: info->nand.ecc.priv = NULL; } #endif - kfree(info); + devm_kfree(&pdev->dev, info); return err; } @@ -2062,15 +2066,15 @@ static int omap_nand_remove(struct platform_device *pdev) dma_release_channel(info->dma); if (info->gpmc_irq_count > 0) - free_irq(info->gpmc_irq_count, info); + devm_free_irq(&pdev->dev, info->gpmc_irq_count, info); if (info->gpmc_irq_fifo > 0) - free_irq(info->gpmc_irq_fifo, info); + devm_free_irq(&pdev->dev, info->gpmc_irq_fifo, info); /* Release NAND device, its internal structures and partitions */ nand_release(&info->mtd); - iounmap(info->nand.IO_ADDR_R); - release_mem_region(info->phys_base, info->mem_size); - kfree(info); + devm_iounmap(&pdev->dev, info->nand.IO_ADDR_R); + devm_release_mem_region(&pdev->dev, info->phys_base, info->mem_size); + devm_kfree(&pdev->dev, info); return 0; }