From patchwork Tue Aug 21 08:54:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sachin Kamat X-Patchwork-Id: 179006 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A1A6B2C0094 for ; Tue, 21 Aug 2012 18:57:22 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T3kG5-0008La-N9; Tue, 21 Aug 2012 08:56:21 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T3kG1-0008L9-Bf for linux-mtd@lists.infradead.org; Tue, 21 Aug 2012 08:56:18 +0000 Received: by pbbrq8 with SMTP id rq8so8744594pbb.36 for ; Tue, 21 Aug 2012 01:56:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=0Mo0l5MEDMQc8B/S7z7A9cWwjB2/maGhH7cEhMFaC3E=; b=ci5pCQQ28NdHJcRSASjvuwEQeNyDVjoK0pbHdAuTJqUcwfRc7nCOfDLiMhRJeYp/U8 c5BoidTxlMDrxN7lWVQEZkP7qsTTpf2VBC0LMMXcEbOXLk6PKQ5TXARxj9Keicc4TUWk szyIJeVqOHgK7w5NRXJ1wcqCxgKSlXbIi/Rx0s9GcxHXo31sIxJFyis+yYc5N3ISWuHj lSTHHmfAfESSfQUSaU3FrSIdRmgdg6ADOADKA9j4c6/szL2HwyMq1L4w3dnjLmfEfuFI lV7NzAfXgyzuqzVoK/aHmPWVIQCvvygZzYb9coP6SvjTv+0Gqx/UEhIAHodoLzQ0XReK PqQQ== Received: by 10.66.76.227 with SMTP id n3mr36275182paw.53.1345539374829; Tue, 21 Aug 2012 01:56:14 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id to6sm1054139pbc.12.2012.08.21.01.56.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Aug 2012 01:56:14 -0700 (PDT) From: Sachin Kamat To: linux-mtd@lists.infradead.org Subject: [PATCH 1/2] mtd: s3c2410: Use devm_* functions Date: Tue, 21 Aug 2012 14:24:09 +0530 Message-Id: <1345539250-4509-1-git-send-email-sachin.kamat@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-Gm-Message-State: ALoCoQmykI/G8FULOCCR+Y/lOSg1rlI2bSm91IwkEipfUwJ2SFPxdCsIjCsKwPya1L/s4IsNgiCa X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: sachin.kamat@linaro.org, patches@linaro.org, dwmw2@infradead.org, dedekind1@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org devm_* functions are device managed functions and make cleanup code simpler and smaller. devm_kzalloc, devm_clk_get and devm_request_and_ioremap functions are used. Signed-off-by: Sachin Kamat --- Compile tested using s3c6400_defconfig and s3c2410_defconfig on the latest linux-next tree. --- drivers/mtd/nand/s3c2410.c | 47 +++++++++---------------------------------- 1 files changed, 10 insertions(+), 37 deletions(-) diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c index e71f7a9..b8a556e 100644 --- a/drivers/mtd/nand/s3c2410.c +++ b/drivers/mtd/nand/s3c2410.c @@ -97,9 +97,8 @@ enum s3c_nand_clk_state { * @mtds: An array of MTD instances on this controoler. * @platform: The platform data for this board. * @device: The platform device we bound to. - * @area: The IO area resource that came from request_mem_region(). * @clk: The clock resource for this controller. - * @regs: The area mapped for the hardware registers described by @area. + * @regs: The area mapped for the hardware registers. * @sel_reg: Pointer to the register controlling the NAND selection. * @sel_bit: The bit in @sel_reg to select the NAND chip. * @mtd_count: The number of MTDs created from this controller. @@ -116,7 +115,6 @@ struct s3c2410_nand_info { /* device info */ struct device *device; - struct resource *area; struct clk *clk; void __iomem *regs; void __iomem *sel_reg; @@ -720,29 +718,12 @@ static int s3c24xx_nand_remove(struct platform_device *pdev) pr_debug("releasing mtd %d (%p)\n", mtdno, ptr); nand_release(&ptr->mtd); } - - kfree(info->mtds); } /* free the common resources */ - if (!IS_ERR(info->clk)) { + if (!IS_ERR(info->clk)) s3c2410_nand_clk_set_state(info, CLOCK_DISABLE); - clk_put(info->clk); - } - - if (info->regs != NULL) { - iounmap(info->regs); - info->regs = NULL; - } - - if (info->area != NULL) { - release_resource(info->area); - kfree(info->area); - info->area = NULL; - } - - kfree(info); return 0; } @@ -937,7 +918,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev) pr_debug("s3c2410_nand_probe(%p)\n", pdev); - info = kzalloc(sizeof(*info), GFP_KERNEL); + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); if (info == NULL) { dev_err(&pdev->dev, "no memory for flash info\n"); err = -ENOMEM; @@ -951,7 +932,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev) /* get the clock source and enable it */ - info->clk = clk_get(&pdev->dev, "nand"); + info->clk = devm_clk_get(&pdev->dev, "nand"); if (IS_ERR(info->clk)) { dev_err(&pdev->dev, "failed to get clock\n"); err = -ENOENT; @@ -963,22 +944,14 @@ static int s3c24xx_nand_probe(struct platform_device *pdev) /* allocate and map the resource */ /* currently we assume we have the one resource */ - res = pdev->resource; + res = pdev->resource; size = resource_size(res); - info->area = request_mem_region(res->start, size, pdev->name); - - if (info->area == NULL) { - dev_err(&pdev->dev, "cannot reserve register region\n"); - err = -ENOENT; - goto exit_error; - } - - info->device = &pdev->dev; - info->platform = plat; - info->regs = ioremap(res->start, size); - info->cpu_type = cpu_type; + info->device = &pdev->dev; + info->platform = plat; + info->cpu_type = cpu_type; + info->regs = devm_request_and_ioremap(&pdev->dev, res); if (info->regs == NULL) { dev_err(&pdev->dev, "cannot reserve register region\n"); err = -EIO; @@ -1001,7 +974,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev) /* allocate our information */ size = nr_sets * sizeof(*info->mtds); - info->mtds = kzalloc(size, GFP_KERNEL); + info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (info->mtds == NULL) { dev_err(&pdev->dev, "failed to allocate mtd storage\n"); err = -ENOMEM;