From patchwork Mon Nov 5 15:10:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 1698471 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id BBD513FCA5 for ; Mon, 5 Nov 2012 15:15:13 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TVOLy-0006Lw-5R; Mon, 05 Nov 2012 15:12:43 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TVOKN-0005Wy-AH for linux-arm-kernel@lists.infradead.org; Mon, 05 Nov 2012 15:11:05 +0000 Received: by mail-we0-f177.google.com with SMTP id u50so2589568wey.36 for ; Mon, 05 Nov 2012 07:11:03 -0800 (PST) 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:in-reply-to:references :x-gm-message-state; bh=Ctaxo58fIqm0AzlK+l9XkGEPOxwsvBokzcQzY6e2s/0=; b=NX9aD8rlDdNeyyqINZ6qciT4u6MO1wyq10Ng5UmwR0h+vGArqVEW73EoTkFDW/OEUW RpezpiJdKQPmR6xdUDYh87sn+UCHTLZ7jXOZbVKY7FSvZ/bOxzq6gif+gmHq6NL/tyOm Og8MHO/5kgOSf97ZdtZmLEl4kyb9S6PrUdZA8aPJwLzM1YT4u5+LCIwhNZhvyLlpdiMY Op6SXphsE6RXyMqdnD+7iLKVjFlgXhQxPVGlgi4X1yRsYRXUGqnROz2gk/hRZUQqP78g PiRrClhadJ2LgI9CbniU2qcNfNDg1CuPl6P8Jee20zoPIvjS99DIDFmEzkovfpOqG/xp JshQ== Received: by 10.216.207.18 with SMTP id m18mr3222647weo.203.1352128262927; Mon, 05 Nov 2012 07:11:02 -0800 (PST) Received: from laptop.vlan14.pylonone.local (78.Red-88-2-49.staticIP.rima-tde.net. [88.2.49.78]) by mx.google.com with ESMTPS id ea9sm12275388wib.11.2012.11.05.07.11.01 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Nov 2012 07:11:02 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sameo@linux.intel.com Subject: [PATCH 7/8] mfd: ab8500-core: Use devm_* memory/IRQ and allocation/free routines Date: Mon, 5 Nov 2012 16:10:35 +0100 Message-Id: <1352128236-11554-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352128236-11554-1-git-send-email-lee.jones@linaro.org> References: <1352128236-11554-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQkH9CEdQBpRfEJoBQElbY3ECP/SX/dChFftNtvGhqDC6mewni27XZ/ZFjz8S02lJZ7fO1eU X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121105_101103_560871_984EA2ED X-CRM114-Status: GOOD ( 15.22 ) 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 [74.125.82.177 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Lee Jones , linus.walleij@stericsson.com, arnd@arndb.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org It is better to use devm_* calls, as they allow for easier and more automatic clean-up. Resources are device allocated, so when a device is freed, so are all associated resources. Acked-by: Linus Walleij Signed-off-by: Lee Jones --- drivers/mfd/ab8500-core.c | 62 ++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c index e7197fe..2a69dc2 100644 --- a/drivers/mfd/ab8500-core.c +++ b/drivers/mfd/ab8500-core.c @@ -1233,7 +1233,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev) int i; u8 value; - ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL); + ab8500 = devm_kzalloc(&pdev->dev, sizeof *ab8500, GFP_KERNEL); if (!ab8500) return -ENOMEM; @@ -1243,10 +1243,8 @@ static int __devinit ab8500_probe(struct platform_device *pdev) ab8500->dev = &pdev->dev; resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!resource) { - ret = -ENODEV; - goto out_free_ab8500; - } + if (!resource) + return -ENODEV; ab8500->irq = resource->start; @@ -1269,7 +1267,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev) ret = get_register_interruptible(ab8500, AB8500_MISC, AB8500_IC_NAME_REG, &value); if (ret < 0) - goto out_free_ab8500; + return ret; ab8500->version = value; } @@ -1277,7 +1275,7 @@ static int __devinit ab8500_probe(struct platform_device *pdev) ret = get_register_interruptible(ab8500, AB8500_MISC, AB8500_REV_REG, &value); if (ret < 0) - goto out_free_ab8500; + return ret; ab8500->chip_id = value; @@ -1294,14 +1292,13 @@ static int __devinit ab8500_probe(struct platform_device *pdev) ab8500->mask_size = AB8500_NUM_IRQ_REGS; ab8500->irq_reg_offset = ab8500_irq_regoffset; } - ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL); + ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL); if (!ab8500->mask) return -ENOMEM; - ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL); - if (!ab8500->oldmask) { - ret = -ENOMEM; - goto out_freemask; - } + ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL); + if (!ab8500->oldmask) + return -ENOMEM; + /* * ab8500 has switched off due to (SWITCH_OFF_STATUS): * 0x01 Swoff bit programming @@ -1355,37 +1352,37 @@ static int __devinit ab8500_probe(struct platform_device *pdev) ret = abx500_register_ops(ab8500->dev, &ab8500_ops); if (ret) - goto out_freeoldmask; + return ret; for (i = 0; i < ab8500->mask_size; i++) ab8500->mask[i] = ab8500->oldmask[i] = 0xff; ret = ab8500_irq_init(ab8500, np); if (ret) - goto out_freeoldmask; + return ret; /* Activate this feature only in ab9540 */ /* till tests are done on ab8500 1p2 or later*/ if (is_ab9540(ab8500)) { - ret = request_threaded_irq(ab8500->irq, NULL, - ab8500_hierarchical_irq, - IRQF_ONESHOT | IRQF_NO_SUSPEND, - "ab8500", ab8500); + ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, + ab8500_hierarchical_irq, + IRQF_ONESHOT | IRQF_NO_SUSPEND, + "ab8500", ab8500); } else { - ret = request_threaded_irq(ab8500->irq, NULL, - ab8500_irq, - IRQF_ONESHOT | IRQF_NO_SUSPEND, - "ab8500", ab8500); + ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, + ab8500_irq, + IRQF_ONESHOT | IRQF_NO_SUSPEND, + "ab8500", ab8500); if (ret) - goto out_freeoldmask; + return ret; } ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs, ARRAY_SIZE(abx500_common_devs), NULL, ab8500->irq_base, ab8500->domain); if (ret) - goto out_freeirq; + return ret; if (is_ab9540(ab8500)) ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, @@ -1396,14 +1393,14 @@ static int __devinit ab8500_probe(struct platform_device *pdev) ARRAY_SIZE(ab8500_devs), NULL, ab8500->irq_base, ab8500->domain); if (ret) - goto out_freeirq; + return ret; if (is_ab9540(ab8500) || is_ab8505(ab8500)) ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs, ARRAY_SIZE(ab9540_ab8505_devs), NULL, ab8500->irq_base, ab8500->domain); if (ret) - goto out_freeirq; + return ret; if (!no_bm) { /* Add battery management devices */ @@ -1424,17 +1421,6 @@ static int __devinit ab8500_probe(struct platform_device *pdev) dev_err(ab8500->dev, "error creating sysfs entries\n"); return ret; - -out_freeirq: - free_irq(ab8500->irq, ab8500); -out_freeoldmask: - kfree(ab8500->oldmask); -out_freemask: - kfree(ab8500->mask); -out_free_ab8500: - kfree(ab8500); - - return ret; } static int __devexit ab8500_remove(struct platform_device *pdev)