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: 164467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wg0-f56.google.com (mail-wg0-f56.google.com [74.125.82.56]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id B2D8FB6FE0 for ; Wed, 13 Jun 2012 04:06:52 +1000 (EST) Received: by wgbds11 with SMTP id ds11sf2919629wgb.11 for ; Tue, 12 Jun 2012 11:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:from:to:cc:subject:date:message-id :x-mailer:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=GT41rl6+FGybx+Pgs2ziy5PtABPqZ54pLs/Maq8L7iE=; b=JF5BxZfTcJu2NVATMCrz0wldcc5bUEqNzGRt8nK9pi7mnq8HuOaTzIXahxx7EQqbIB mVlNXPk0cyygotwAiVNUiN8JLsmzb00aBnSKWzuMkmxeooHr/ACTrwBx9vXldyZIzCaf FkKENbzlpQS+hkPDFhbHl/ZxO9Ul3FKphRXbM= Received: by 10.180.102.226 with SMTP id fr2mr800617wib.4.1339524409505; Tue, 12 Jun 2012 11:06:49 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.28.138 with SMTP id g10ls294422eea.0.gmail; Tue, 12 Jun 2012 11:06:48 -0700 (PDT) Received: by 10.14.29.66 with SMTP id h42mr5800656eea.13.1339524408939; Tue, 12 Jun 2012 11:06:48 -0700 (PDT) Received: by 10.14.29.66 with SMTP id h42mr5800655eea.13.1339524408885; Tue, 12 Jun 2012 11:06:48 -0700 (PDT) Received: from eu1sys200aog115.obsmtp.com (eu1sys200aog115.obsmtp.com. [207.126.144.139]) by gmr-mx.google.com with SMTP id b15si19266054een.0.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; 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: [rtc-linux] [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-Original-Sender: linus.walleij@stericsson.com X-Original-Authentication-Results: gmr-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 Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , 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; }