From patchwork Thu Aug 11 03:20:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todd Poynor X-Patchwork-Id: 109490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ww0-f56.google.com (mail-ww0-f56.google.com [74.125.82.56]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 4D54DB6F89 for ; Thu, 11 Aug 2011 13:21:09 +1000 (EST) Received: by wwf10 with SMTP id 10sf3811129wwf.11 for ; Wed, 10 Aug 2011 20:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer: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=9jjdHqiFLmI/EY54jY1fMdY1OQBa7/I3yYOTu9aVs74=; b=osQlQM0K14ut21tnOQCyZ4wbf+bxwFeHoA1iEQT/SIREV//DBc+oxhb16/wHKjip7m 0usUA+g93WnX42FoCcmQVrwirPdXFWAUZcROLSj/TtjI3bdcfiTj1ilnGbhjcnpFimNp X4Sga9uJWBTJfZvanp9WiZQT/t7G8zxiwX3qs= Received: by 10.216.59.203 with SMTP id s53mr1936270wec.3.1313032864457; Wed, 10 Aug 2011 20:21:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.135.72 with SMTP id t48ls1306042eei.7.canary; Wed, 10 Aug 2011 20:21:03 -0700 (PDT) Received: by 10.14.47.196 with SMTP id t44mr331230eeb.2.1313032863296; Wed, 10 Aug 2011 20:21:03 -0700 (PDT) Received: by 10.14.47.196 with SMTP id t44mr331229eeb.2.1313032863279; Wed, 10 Aug 2011 20:21:03 -0700 (PDT) Received: from smtp-out.google.com (hpaq8.eem.corp.google.com [172.25.149.8]) by gmr-mx.google.com with ESMTPS id k20si2320278eea.2.2011.08.10.20.21.03 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 10 Aug 2011 20:21:03 -0700 (PDT) Received-SPF: pass (google.com: domain of toddpoynor@google.com designates 172.25.149.8 as permitted sender) Received: from wpaz17.hot.corp.google.com (wpaz17.hot.corp.google.com [172.24.198.81]) by smtp-out.google.com with ESMTP id p7B3Kwu1029087; Wed, 10 Aug 2011 20:20:58 -0700 Received: from conslugarocko.mtv.corp.google.com (conslugarocko.mtv.corp.google.com [172.18.102.26]) by wpaz17.hot.corp.google.com with ESMTP id p7B3KpoG031592; Wed, 10 Aug 2011 20:20:51 -0700 Received: by conslugarocko.mtv.corp.google.com (Postfix, from userid 115684) id 1321C2342D0; Wed, 10 Aug 2011 20:20:51 -0700 (PDT) From: Todd Poynor To: John Stultz , Alessandro Zummo Cc: rtc-linux@googlegroups.com, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, Todd Poynor Subject: [rtc-linux] [PATCH] rtc: twl: Fix registration vs. init order Date: Wed, 10 Aug 2011 20:20:36 -0700 Message-Id: <1313032836-347-1-git-send-email-toddpoynor@google.com> X-Mailer: git-send-email 1.7.3.1 X-Original-Sender: toddpoynor@google.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of toddpoynor@google.com designates 172.25.149.8 as permitted sender) smtp.mail=toddpoynor@google.com; dkim=pass (test mode) header.i=@google.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: , Only register as an RTC device after the hardware has been successfully initialized. The RTC class driver will call back to this driver to read a pending alarm, and other drivers watching for new devices on the RTC class may read the RTC time upon registration. Such access might occur while the RTC is stopped, prior to clearing pending alarms, etc. The new ordering also avoids leaving the platform device drvdata set to an unregistered struct rtc_device * on probe errors. Signed-off-by: Todd Poynor --- This version generated after applying: [PATCH] rtc-twl: Switch to using threaded irq http://patchwork.ozlabs.org/patch/97978/ drivers/rtc/rtc-twl.c | 52 ++++++++++++++++++++++-------------------------- 1 files changed, 24 insertions(+), 28 deletions(-) diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c index 9677bbc..20687d5 100644 --- a/drivers/rtc/rtc-twl.c +++ b/drivers/rtc/rtc-twl.c @@ -420,24 +420,12 @@ static struct rtc_class_ops twl_rtc_ops = { static int __devinit twl_rtc_probe(struct platform_device *pdev) { struct rtc_device *rtc; - int ret = 0; + int ret = -EINVAL; int irq = platform_get_irq(pdev, 0); u8 rd_reg; if (irq <= 0) - return -EINVAL; - - rtc = rtc_device_register(pdev->name, - &pdev->dev, &twl_rtc_ops, THIS_MODULE); - if (IS_ERR(rtc)) { - ret = PTR_ERR(rtc); - dev_err(&pdev->dev, "can't register RTC device, err %ld\n", - PTR_ERR(rtc)); - goto out0; - - } - - platform_set_drvdata(pdev, rtc); + goto out1; ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG); if (ret < 0) @@ -454,14 +442,6 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev) if (ret < 0) goto out1; - ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt, - IRQF_TRIGGER_RISING, - dev_name(&rtc->dev), rtc); - if (ret < 0) { - dev_err(&pdev->dev, "IRQ is not free.\n"); - goto out1; - } - if (twl_class_is_6030()) { twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK, REG_INT_MSK_LINE_A); @@ -472,28 +452,44 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev) /* Check RTC module status, Enable if it is off */ ret = twl_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG); if (ret < 0) - goto out2; + goto out1; if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) { dev_info(&pdev->dev, "Enabling TWL-RTC.\n"); rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M; ret = twl_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG); if (ret < 0) - goto out2; + goto out1; } /* init cached IRQ enable bits */ ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG); if (ret < 0) + goto out1; + + rtc = rtc_device_register(pdev->name, + &pdev->dev, &twl_rtc_ops, THIS_MODULE); + if (IS_ERR(rtc)) { + ret = PTR_ERR(rtc); + dev_err(&pdev->dev, "can't register RTC device, err %ld\n", + PTR_ERR(rtc)); + goto out1; + } + + ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt, + IRQF_TRIGGER_RISING, + dev_name(&rtc->dev), rtc); + if (ret < 0) { + dev_err(&pdev->dev, "IRQ is not free.\n"); goto out2; + } - return ret; + platform_set_drvdata(pdev, rtc); + return 0; out2: - free_irq(irq, rtc); -out1: rtc_device_unregister(rtc); -out0: +out1: return ret; }