From patchwork Sun Oct 14 14:03:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannu Heikkinen X-Patchwork-Id: 191362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lb0-f184.google.com (mail-lb0-f184.google.com [209.85.217.184]) (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 680F12C0095 for ; Mon, 15 Oct 2012 01:03:53 +1100 (EST) Received: by mail-lb0-f184.google.com with SMTP id gm13sf1520022lbb.11 for ; Sun, 14 Oct 2012 07:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:x-beenthere:received-spf:from:to:subject:date :message-id:x-mailer:in-reply-to:references: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=8MC43SkbPLSoVV/dIqBS34c4cIWXXpBjaaayQqKZuoQ=; b=QUxaO8qVytEuLd3aP8U6eWO9l4tI2AQTY40/r+cHB5uuW8rwQtFeQbhOxYUHIafxZu 2ZP+TzphhVdRGh46lwAo3a0Gzd5NABVzCz0Inlvp9143PrwJ4Q40ai4UjN/di/tJiluB qzhxovQnX+ByHjk1itWH6irpMhxVCvMusOCTk+yUgq3KnNTevhrj/OX9x9S44Z3xVkzo eYfMd6DYyy9m0MLrmXNJI2Rd5SxPgP9sL85tdx1XYFaIxE/TL5MLC9m8yvMO2ZUNXF3h I/RaCgpm06wLWfKcNT6n7uB97XIzWE8oUBMG8MCeNHvxCiOBtaCg8x/9//U93ja0dRtX w6fg== Received: by 10.204.130.4 with SMTP id q4mr678207bks.27.1350223429939; Sun, 14 Oct 2012 07:03:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.204.15.205 with SMTP id l13ls483899bka.8.gmail; Sun, 14 Oct 2012 07:03:49 -0700 (PDT) Received: by 10.204.6.19 with SMTP id 19mr597034bkx.8.1350223429107; Sun, 14 Oct 2012 07:03:49 -0700 (PDT) Received: by 10.204.6.19 with SMTP id 19mr597033bkx.8.1350223429090; Sun, 14 Oct 2012 07:03:49 -0700 (PDT) Received: from relay.sigmatic.fi (relay.sigmatic.fi. [80.69.161.51]) by gmr-mx.google.com with ESMTPS id t1si1307620bkt.1.2012.10.14.07.03.48 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 14 Oct 2012 07:03:49 -0700 (PDT) Received-SPF: pass (google.com: domain of hannuxx@iki.fi designates 80.69.161.51 as permitted sender) client-ip=80.69.161.51; Received: (qmail 6408 invoked from network); 14 Oct 2012 14:03:48 -0000 Received: from unknown (HELO localhost) (hannu@apokalypsis.fi@88.115.119.222) by mail1.sigmatic.fi with ESMTPA; 14 Oct 2012 14:03:48 -0000 From: Hannu Heikkinen To: linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com, a.zummo@towertech.it, davinci-linux-open-source@linux.davincidsp.com, nsekhar@ti.com Subject: [rtc-linux] [PATCH v3] rtc: davinci: clean up probe/remove routines Date: Sun, 14 Oct 2012 17:03:46 +0300 Message-Id: <1350223426-5369-1-git-send-email-hannuxx@iki.fi> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1350207822-4857-1-git-send-email-hannuxx@iki.fi> References: <1350207822-4857-1-git-send-email-hannuxx@iki.fi> X-Original-Sender: hannuxx@iki.fi X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of hannuxx@iki.fi designates 80.69.161.51 as permitted sender) smtp.mail=hannuxx@iki.fi 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: , Use the devres managed resource functions in the probe routine. Also affects the remove routine where the previously used free and release functions are not needed. The devm_* functions eliminate the need for manual resource releasing and simplify error handling. Resources allocated by devm_* are freed automatically on driver detach. Signed-off-by: Hannu Heikkinen --- drivers/rtc/rtc-davinci.c | 59 +++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c index 14c2109..4a10b4b 100644 --- a/drivers/rtc/rtc-davinci.c +++ b/drivers/rtc/rtc-davinci.c @@ -119,8 +119,6 @@ static DEFINE_SPINLOCK(davinci_rtc_lock); struct davinci_rtc { struct rtc_device *rtc; void __iomem *base; - resource_size_t pbase; - size_t base_size; int irq; }; @@ -482,46 +480,32 @@ static int __init davinci_rtc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct davinci_rtc *davinci_rtc; - struct resource *res, *mem; + struct resource *res; int ret = 0; - davinci_rtc = kzalloc(sizeof(struct davinci_rtc), GFP_KERNEL); + davinci_rtc = devm_kzalloc(&pdev->dev, sizeof(struct davinci_rtc), + GFP_KERNEL); if (!davinci_rtc) { dev_dbg(dev, "could not allocate memory for private data\n"); return -ENOMEM; } - davinci_rtc->irq = platform_get_irq(pdev, 0); - if (davinci_rtc->irq < 0) { - dev_err(dev, "no RTC irq\n"); - ret = davinci_rtc->irq; - goto fail1; - } - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(dev, "no mem resource\n"); - ret = -EINVAL; - goto fail1; + return -EINVAL; } - davinci_rtc->pbase = res->start; - davinci_rtc->base_size = resource_size(res); - - mem = request_mem_region(davinci_rtc->pbase, davinci_rtc->base_size, - pdev->name); - if (!mem) { - dev_err(dev, "RTC registers at %08x are not free\n", - davinci_rtc->pbase); - ret = -EBUSY; - goto fail1; + davinci_rtc->base = devm_request_and_ioremap(&pdev->dev, res); + if (!davinci_rtc->base) { + dev_err(&pdev->dev, "Unable to request mem region and grab IOs for device.\n"); + return -EBUSY; } - davinci_rtc->base = ioremap(davinci_rtc->pbase, davinci_rtc->base_size); - if (!davinci_rtc->base) { - dev_err(dev, "unable to ioremap MEM resource\n"); - ret = -ENOMEM; - goto fail2; + davinci_rtc->irq = platform_get_irq(pdev, 0); + if (davinci_rtc->irq < 0) { + dev_err(dev, "no RTC irq\n"); + return davinci_rtc->irq; } platform_set_drvdata(pdev, davinci_rtc); @@ -529,9 +513,10 @@ static int __init davinci_rtc_probe(struct platform_device *pdev) davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &davinci_rtc_ops, THIS_MODULE); if (IS_ERR(davinci_rtc->rtc)) { + ret = PTR_ERR(davinci_rtc->rtc); dev_err(dev, "unable to register RTC device, err %ld\n", PTR_ERR(davinci_rtc->rtc)); - goto fail3; + return ret; } rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG); @@ -545,7 +530,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev) 0, "davinci_rtc", davinci_rtc); if (ret < 0) { dev_err(dev, "unable to register davinci RTC interrupt\n"); - goto fail4; + goto err_dev_unreg; } /* Enable interrupts */ @@ -559,15 +544,8 @@ static int __init davinci_rtc_probe(struct platform_device *pdev) return 0; -fail4: +err_dev_unreg: rtc_device_unregister(davinci_rtc->rtc); -fail3: - platform_set_drvdata(pdev, NULL); - iounmap(davinci_rtc->base); -fail2: - release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size); -fail1: - kfree(davinci_rtc); return ret; } @@ -584,13 +562,8 @@ static int __devexit davinci_rtc_remove(struct platform_device *pdev) rtc_device_unregister(davinci_rtc->rtc); - iounmap(davinci_rtc->base); - release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size); - platform_set_drvdata(pdev, NULL); - kfree(davinci_rtc); - return 0; }