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: 10825 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4D73C23E1B for ; Tue, 21 Aug 2012 08:56:17 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id C9468A180A3 for ; Tue, 21 Aug 2012 08:56:08 +0000 (UTC) Received: by iadj38 with SMTP id j38so3365206iad.11 for ; Tue, 21 Aug 2012 01:56:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=0Mo0l5MEDMQc8B/S7z7A9cWwjB2/maGhH7cEhMFaC3E=; b=pU1HfpAY1ivBNxvRPrpdxIRY3TDyqBfpatzHTn/RROsm0ccJbbRUL5sZW5vaPPG/mO 3SezosjYgnJFsmU6Whp2Qbtv24LIWr6cevTG85TaeBk7Dk5PCt3OB8YgG1nYMa+peq4Z NmwUmUeyUGnWURQpIJDnllduisrnWSPQZ504UfHpAt2ve2XkVFiO6zKaXRRSwIIkmXRJ CboZs7C6GCaDuWAnvMUeK1iMZV5bMersAAI05bHmGT6fiFt1NtvqdEqilKZTr/GMHSQo IuwcOs8x1H8yi2YLV6Z1b2jvqmdOgB+kMZid2hq+4H4u/mvICWFbRicdsEPyNMALxOvc f/vQ== Received: by 10.50.236.8 with SMTP id uq8mr13557145igc.1.1345539376180; Tue, 21 Aug 2012 01:56:16 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp131871igc; Tue, 21 Aug 2012 01:56:15 -0700 (PDT) Received: by 10.66.85.70 with SMTP id f6mr36427738paz.7.1345539375538; Tue, 21 Aug 2012 01:56:15 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id px6si2148867pbc.64.2012.08.21.01.56.15 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Aug 2012 01:56:15 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of sachin.kamat@linaro.org) smtp.mail=sachin.kamat@linaro.org Received: by pbcmd12 with SMTP id md12so9064065pbc.37 for ; Tue, 21 Aug 2012 01:56:14 -0700 (PDT) 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 Cc: dedekind1@gmail.com, sachin.kamat@linaro.org, patches@linaro.org, dwmw2@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: ALoCoQnuXvL0DuMJfM1D/9WHyN/TO5K0rasjBkSjla1EA5ISqCCXMeBOqvhFcK350gVXFHi8xM2o 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;