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: 12671 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 3DF7223EF8 for ; Mon, 5 Nov 2012 15:11:05 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id D3D0EA19A04 for ; Mon, 5 Nov 2012 15:11:04 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so7810038iej.11 for ; Mon, 05 Nov 2012 07:11:04 -0800 (PST) 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:in-reply-to:references :x-gm-message-state; bh=Ctaxo58fIqm0AzlK+l9XkGEPOxwsvBokzcQzY6e2s/0=; b=ZLHmWXHryKvf3rmIo2uIQ/HNkEa/8MMJ1kXBlL7i8dvIdPJjWTT4QXs5Xdx+chEUc4 u0svSNj1yCQ5c+U0wdTw+aCLurxS38cMuUgdHedPptUt/mlxX8TICksuNHyIFtgnlO64 YIukwGBpuzfVV3DSzMlpp1mUrBE3qG9Hhrna42au9/GGSTGXw1nzacN/Ig/sKGJehHbz vdsuE7gZOc4AYtBsDM8lkxjXm71up1WpNjQKnaKl3+MdIYjZLc3jSv8N/vF6j9wKd0Ce jMSq7hYovP8zsEe3/7HU5dJDl9/J6Znh53rSgiP99PVqqbNOsRRBFeTjoSfL0ekv9+mI xH8g== Received: by 10.42.203.146 with SMTP id fi18mr8416523icb.18.1352128264640; Mon, 05 Nov 2012 07:11:04 -0800 (PST) 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.67.148 with SMTP id n20csp231265igt; Mon, 5 Nov 2012 07:11:04 -0800 (PST) Received: by 10.180.105.168 with SMTP id gn8mr13651199wib.10.1352128263414; Mon, 05 Nov 2012 07:11:03 -0800 (PST) Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by mx.google.com with ESMTPS id gy10si4350829wib.4.2012.11.05.07.11.03 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Nov 2012 07:11:03 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.51 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.51; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.51 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wg0-f51.google.com with SMTP id ed3so3023637wgb.20 for ; Mon, 05 Nov 2012 07:11:03 -0800 (PST) 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 Cc: arnd@arndb.de, linus.walleij@stericsson.com, Lee Jones 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: ALoCoQmSHFaRwZDcQZ0AM/8bh2xruK/lwa/DDEwuGoggkg7BzHicUjiBtCT3o7rbHqhWQuqgG9Tx 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)