From patchwork Tue Jun 12 18:06:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9237 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 9521123E4F for ; Tue, 12 Jun 2012 18:06:50 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 64E2DA1840A for ; Tue, 12 Jun 2012 18:06:50 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so4029725yen.11 for ; Tue, 12 Jun 2012 11:06:50 -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:mime-version:content-type :x-gm-message-state; bh=V3zpuJ9/g11NAwqIu0QyEuM94P+tl1fZraEx1LAlsGI=; b=ZzNbk4zqPqU3xnAyV0UYbOn7GJ276CZmw4W93nh2MfAtHJgRC93w0kQR+ZrXjCVBE4 0Atxtj2LbV5mhQy41YExRfZKZ61PxDgaEasYxqB/W1xsca06ibG2FBEZfRy/waatsGkd hNXLFixfxsfwsXGZBIujbrreo8nyb1OGD+LkpCvz6/LigBdiOOtgoPZa6TJiBc/2iEYV yjgJ+LvWkB/ExDg/+Yptat1Mdu6io7TBQvz1GZnQqC6ZAQwZx3/zgx1vRhKQuYaCSSg0 7qFl0rr/29crMAeuipgcpthtrKuUu3ZPDCxep8yNE1z6DT429cScoeJqLiWzIv3xlIaf TKlg== Received: by 10.50.203.39 with SMTP id kn7mr9051143igc.53.1339524410049; Tue, 12 Jun 2012 11:06:50 -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.231.24.148 with SMTP id v20csp181080ibb; Tue, 12 Jun 2012 11:06:49 -0700 (PDT) Received: by 10.14.127.78 with SMTP id c54mr6136466eei.217.1339524408895; Tue, 12 Jun 2012 11:06:48 -0700 (PDT) Received: from eu1sys200aog115.obsmtp.com (eu1sys200aog115.obsmtp.com. [207.126.144.139]) by mx.google.com with SMTP id z14si9566047eef.135.2012.06.12.11.06.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 12 Jun 2012 11:06:48 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.139 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.139; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.139 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob115.postini.com ([207.126.147.11]) with SMTP ID DSNKT9eFL4BTs7SFimWCLCIbRNI/JFAjTbuB@postini.com; Tue, 12 Jun 2012 18:06:48 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id E34A8B9; Tue, 12 Jun 2012 17:58:16 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id E273BFC5; Tue, 12 Jun 2012 18:06:35 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 9C50124C07C; Tue, 12 Jun 2012 20:06:25 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 12 Jun 2012 20:06:35 +0200 From: Linus Walleij To: Andrew Morton Cc: Alessandro Zummo , , Linus Walleij Subject: [PATCH 2/2] rtc: coh901331: use devm allocation Date: Tue, 12 Jun 2012 20:06:31 +0200 Message-ID: <1339524391-5493-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.9.2 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkRhK1x4Rfqi5rERUs2WSGyZ0X0M2NCyukoHCdnlN27MJuaSrtG1tbo0ydo+HzpqTICFTcr From: Linus Walleij Allocate memory, region, remap and irq for device state using devm_* helpers to simplify memory accounting. Signed-off-by: Linus Walleij --- drivers/rtc/rtc-coh901331.c | 50 +++++++++++++------------------------------ 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c index 5866502..76b2156 100644 --- a/drivers/rtc/rtc-coh901331.c +++ b/drivers/rtc/rtc-coh901331.c @@ -155,14 +155,10 @@ static int __exit coh901331_remove(struct platform_device *pdev) struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); if (rtap) { - free_irq(rtap->irq, rtap); rtc_device_unregister(rtap->rtc); clk_unprepare(rtap->clk); clk_put(rtap->clk); - iounmap(rtap->virtbase); - release_mem_region(rtap->phybase, rtap->physize); platform_set_drvdata(pdev, NULL); - kfree(rtap); } return 0; @@ -175,42 +171,36 @@ static int __init coh901331_probe(struct platform_device *pdev) struct coh901331_port *rtap; struct resource *res; - rtap = kzalloc(sizeof(struct coh901331_port), GFP_KERNEL); + rtap = devm_kzalloc(&pdev->dev, + sizeof(struct coh901331_port), GFP_KERNEL); if (!rtap) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - ret = -ENOENT; - goto out_no_resource; - } + if (!res) + return -ENOENT; + rtap->phybase = res->start; rtap->physize = resource_size(res); - if (request_mem_region(rtap->phybase, rtap->physize, - "rtc-coh901331") == NULL) { - ret = -EBUSY; - goto out_no_memregion; - } + if (devm_request_mem_region(&pdev->dev, rtap->phybase, rtap->physize, + "rtc-coh901331") == NULL) + return -EBUSY; - rtap->virtbase = ioremap(rtap->phybase, rtap->physize); - if (!rtap->virtbase) { - ret = -ENOMEM; - goto out_no_remap; - } + rtap->virtbase = devm_ioremap(&pdev->dev, rtap->phybase, rtap->physize); + if (!rtap->virtbase) + return -ENOMEM; rtap->irq = platform_get_irq(pdev, 0); - if (request_irq(rtap->irq, coh901331_interrupt, 0, - "RTC COH 901 331 Alarm", rtap)) { - ret = -EIO; - goto out_no_irq; - } + if (devm_request_irq(&pdev->dev, rtap->irq, coh901331_interrupt, 0, + "RTC COH 901 331 Alarm", rtap)) + return -EIO; rtap->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(rtap->clk)) { ret = PTR_ERR(rtap->clk); dev_err(&pdev->dev, "could not get clock\n"); - goto out_no_clk; + return ret; } /* We enable/disable the clock only to assure it works */ @@ -236,16 +226,6 @@ static int __init coh901331_probe(struct platform_device *pdev) clk_unprepare(rtap->clk); out_no_clk_prepenable: clk_put(rtap->clk); - out_no_clk: - free_irq(rtap->irq, rtap); - out_no_irq: - iounmap(rtap->virtbase); - out_no_remap: - platform_set_drvdata(pdev, NULL); - out_no_memregion: - release_mem_region(rtap->phybase, SZ_4K); - out_no_resource: - kfree(rtap); return ret; }