From patchwork Sun Mar 26 14:41:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 9645407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 904BE602BF for ; Mon, 27 Mar 2017 07:09:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 827A22832D for ; Mon, 27 Mar 2017 07:09:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75A9A28356; Mon, 27 Mar 2017 07:09:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35AFA2832D for ; Mon, 27 Mar 2017 07:09:04 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 21B97266A65; Mon, 27 Mar 2017 09:07:59 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A8053266BF6; Sun, 26 Mar 2017 16:42:44 +0200 (CEST) Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com [209.85.128.173]) by alsa0.perex.cz (Postfix) with ESMTP id 8189B266961 for ; Sun, 26 Mar 2017 16:42:42 +0200 (CEST) Received: by mail-wr0-f173.google.com with SMTP id l43so22369302wre.1 for ; Sun, 26 Mar 2017 07:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KyYJuXgfmXbBg0TlwaGs5+JOExj1Z5/7bWtZEM3EPug=; b=RmkhsECumSIjB0qIeRMuInvFcW7RdHqPNg1I0f8XJqcY3KPhLQVP44YVvWREAGyIGD 0f4ZwbO8vtd8rUhcyLaRr4ZTyCMSasL0tQLoccaFDjwdhglB6qDmDSCyZwsQKOHQohlS RNulVgVg4P/AR9koeiFe0YJ6Svor5R2Zyi6iY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KyYJuXgfmXbBg0TlwaGs5+JOExj1Z5/7bWtZEM3EPug=; b=sBe+5LVAOSVceyrHaSY8O3JbGiomzN1fENmgXDWV9QB5vSdmvkbBInVmMI7KuQwmym UX/LyAcG5BbdMbNzoQwBIGN9GME22ucjJlv2kA1iMr749BRf1LPd7ynuzxMt+DnUQOWL g0Z+TCz3xLlShMXs8MrMYTXx9t3Yi8d12uQ4Bt5xhM2cotm8iIjmzVAx02Fc6fD/fYs1 dcnBwdbnFY3p8Se1elk4vXdYwdPEvEEvjoMqmFcYE1mX7uIiH/Via0cXvbRN4d4yFn7N VfwXMVrAn6lsihQP5O9XQdRd/GWgP2ny6CrDIMTRFGTB/nhEzwy8UZfuGoLiAcj1K8Sf 3TtA== X-Gm-Message-State: AFeK/H2ERtHJZwvloHq1NnIw6EgZS5hyqoJFyDwzbc54SueY4SotfH5cM1XmJkUfhWe6gYm/ X-Received: by 10.28.153.20 with SMTP id b20mr589736wme.76.1490539361680; Sun, 26 Mar 2017 07:42:41 -0700 (PDT) Received: from localhost.localdomain (li1529-187.members.linode.com. [139.162.244.187]) by smtp.gmail.com with ESMTPSA id l90sm10619516wmi.25.2017.03.26.07.42.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Mar 2017 07:42:40 -0700 (PDT) From: Leo Yan To: Russell King , Dmitry Torokhov , Alessandro Zummo , Alexandre Belloni , Linus Walleij , Baptiste Reynal , Alex Williamson , Jaroslav Kysela , Takashi Iwai , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, alsa-devel@alsa-project.org Date: Sun, 26 Mar 2017 22:41:52 +0800 Message-Id: <1490539314-9681-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490539314-9681-1-git-send-email-leo.yan@linaro.org> References: <1490539314-9681-1-git-send-email-leo.yan@linaro.org> X-Mailman-Approved-At: Mon, 27 Mar 2017 09:07:53 +0200 Cc: Leo Yan Subject: [alsa-devel] [PATCH 3/5] drivers/rtc/rtc-pl031.c: Convert to use devm_*() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Convert driver to use devm_*() APIs so rely on driver model core layer to manage resources. This eliminates error path boilerplate and makes code neat. Signed-off-by: Leo Yan Acked-by: Linus Walleij --- drivers/rtc/rtc-pl031.c | 59 +++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c index e1687e1..1699a17 100644 --- a/drivers/rtc/rtc-pl031.c +++ b/drivers/rtc/rtc-pl031.c @@ -304,15 +304,8 @@ static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int pl031_remove(struct amba_device *adev) { - struct pl031_local *ldata = dev_get_drvdata(&adev->dev); - dev_pm_clear_wake_irq(&adev->dev); device_init_wakeup(&adev->dev, false); - free_irq(adev->irq[0], ldata); - rtc_device_unregister(ldata->rtc); - iounmap(ldata->base); - kfree(ldata); - amba_release_regions(adev); return 0; } @@ -325,23 +318,15 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id) struct rtc_class_ops *ops = &vendor->ops; unsigned long time, data; - ret = amba_request_regions(adev, NULL); - if (ret) - goto err_req; + ldata = devm_kzalloc(&adev->dev, sizeof(*ldata), GFP_KERNEL); + if (!ldata) + return -ENOMEM; - ldata = kzalloc(sizeof(struct pl031_local), GFP_KERNEL); - if (!ldata) { - ret = -ENOMEM; - goto out; - } ldata->vendor = vendor; - ldata->base = ioremap(adev->res.start, resource_size(&adev->res)); - - if (!ldata->base) { - ret = -ENOMEM; - goto out_no_remap; - } + ldata->base = devm_ioremap_resource(&adev->dev, &adev->res); + if (IS_ERR(ldata->base)) + return PTR_ERR(ldata->base); amba_set_drvdata(adev, ldata); @@ -374,32 +359,18 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id) } device_init_wakeup(&adev->dev, true); - ldata->rtc = rtc_device_register("pl031", &adev->dev, ops, - THIS_MODULE); - if (IS_ERR(ldata->rtc)) { - ret = PTR_ERR(ldata->rtc); - goto out_no_rtc; - } + ldata->rtc = devm_rtc_device_register(&adev->dev, "pl031", ops, + THIS_MODULE); + if (IS_ERR(ldata->rtc)) + return PTR_ERR(ldata->rtc); + + ret = devm_request_irq(&adev->dev, adev->irq[0], pl031_interrupt, + vendor->irqflags, "rtc-pl031", ldata); + if (ret) + return ret; - if (request_irq(adev->irq[0], pl031_interrupt, - vendor->irqflags, "rtc-pl031", ldata)) { - ret = -EIO; - goto out_no_irq; - } dev_pm_set_wake_irq(&adev->dev, adev->irq[0]); return 0; - -out_no_irq: - rtc_device_unregister(ldata->rtc); -out_no_rtc: - iounmap(ldata->base); -out_no_remap: - kfree(ldata); -out: - amba_release_regions(adev); -err_req: - - return ret; } /* Operations for the original ARM version */