From patchwork Wed Jul 27 07:07:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todd Poynor X-Patchwork-Id: 1010892 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6R78YwK030486 for ; Wed, 27 Jul 2011 07:08:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752553Ab1G0HIS (ORCPT ); Wed, 27 Jul 2011 03:08:18 -0400 Received: from smtp-out.google.com ([74.125.121.67]:33359 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751684Ab1G0HIR (ORCPT ); Wed, 27 Jul 2011 03:08:17 -0400 Received: from hpaq2.eem.corp.google.com (hpaq2.eem.corp.google.com [172.25.149.2]) by smtp-out.google.com with ESMTP id p6R77jdk023266; Wed, 27 Jul 2011 00:07:46 -0700 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1311750466; bh=9DcB2H7BS3LH57dJDJSU8DBoNPE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=X88vvXEV98sDeiZYVijPCi9IA07yT7DeJ/yi/xfd8RXFYWu2Z0Sca29Ae8BPnsKha 1Lln1OW2TCjqQlDvKCFng== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=R7yDafXzjKt9bvPAjphaGD1uiuJUq9HBp6zuX0hh6zJqOk+PT5epbcQnLouJ7XdWN BcPDmXwRf0/klIAYAHlvQ== Received: from conslugarocko.mtv.corp.google.com (conslugarocko.mtv.corp.google.com [172.18.102.26]) by hpaq2.eem.corp.google.com with ESMTP id p6R77bEP012784; Wed, 27 Jul 2011 00:07:38 -0700 Received: by conslugarocko.mtv.corp.google.com (Postfix, from userid 115684) id 9578E2342BB; Wed, 27 Jul 2011 00:07:37 -0700 (PDT) From: Todd Poynor To: Alessandro Zummo Cc: rtc-linux@googlegroups.com, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, Todd Poynor Subject: [PATCH 2/2] rtc: twl: Fix registration vs. init order Date: Wed, 27 Jul 2011 00:07:21 -0700 Message-Id: <1311750441-5559-2-git-send-email-toddpoynor@google.com> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1311750441-5559-1-git-send-email-toddpoynor@google.com> References: <1311750441-5559-1-git-send-email-toddpoynor@google.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 27 Jul 2011 07:08:34 +0000 (UTC) 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 --- 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 ece41b9..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; }