From patchwork Fri Oct 4 19:49:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pekon gupta X-Patchwork-Id: 2990061 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 6794CBF923 for ; Fri, 4 Oct 2013 19:51:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75936201EA for ; Fri, 4 Oct 2013 19:51:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77403201D3 for ; Fri, 4 Oct 2013 19:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753943Ab3JDTv1 (ORCPT ); Fri, 4 Oct 2013 15:51:27 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:39917 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753791Ab3JDTv0 (ORCPT ); Fri, 4 Oct 2013 15:51:26 -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 r94JotCj003116; Fri, 4 Oct 2013 14:50:55 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r94JotMJ006740; Fri, 4 Oct 2013 14:50:55 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Fri, 4 Oct 2013 14:50:55 -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 r94JoG5j017635; Fri, 4 Oct 2013 14:50:50 -0500 From: Pekon Gupta To: , , , , CC: , , , , , , , , , , , , Pekon Gupta Subject: [PATCH v7 6/6] mtd: nand: omap: updated devm_xx for all resource allocation and free calls Date: Sat, 5 Oct 2013 01:19:48 +0530 Message-ID: <1380916188-24206-7-git-send-email-pekon@ti.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1380916188-24206-1-git-send-email-pekon@ti.com> References: <1380916188-24206-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=-4.2 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, 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 --- 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; }