[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-3.0 / sakoman / 0010-fix-registration-vs-init-order.patch
1 From patchwork Wed Jul 27 07:07:21 2011
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 Subject: [2/2] rtc: twl: Fix registration vs. init order
6 Date: Wed, 27 Jul 2011 07:07:21 -0000
7 From: Todd Poynor <toddpoynor@google.com>
8 X-Patchwork-Id: 1010892
9 Message-Id: <1311750441-5559-2-git-send-email-toddpoynor@google.com>
10 To: Alessandro Zummo <a.zummo@towertech.it>
11 Cc: rtc-linux@googlegroups.com, linux-omap@vger.kernel.org,
12 linux-kernel@vger.kernel.org, Todd Poynor <toddpoynor@google.com>
14 Only register as an RTC device after the hardware has been
15 successfully initialized. The RTC class driver will call
16 back to this driver to read a pending alarm, and other
17 drivers watching for new devices on the RTC class may
18 read the RTC time upon registration. Such access might
19 occur while the RTC is stopped, prior to clearing
20 pending alarms, etc.
22 The new ordering also avoids leaving the platform
23 device drvdata set to an unregistered struct rtc_device *
24 on probe errors.
26 Signed-off-by: Todd Poynor <toddpoynor@google.com>
28 ---
29 drivers/rtc/rtc-twl.c | 52 ++++++++++++++++++++++--------------------------
30 1 files changed, 24 insertions(+), 28 deletions(-)
32 diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
33 index ece41b9..20687d5 100644
34 --- a/drivers/rtc/rtc-twl.c
35 +++ b/drivers/rtc/rtc-twl.c
36 @@ -420,24 +420,12 @@ static struct rtc_class_ops twl_rtc_ops = {
37 static int __devinit twl_rtc_probe(struct platform_device *pdev)
38 {
39 struct rtc_device *rtc;
40 - int ret = 0;
41 + int ret = -EINVAL;
42 int irq = platform_get_irq(pdev, 0);
43 u8 rd_reg;
45 if (irq <= 0)
46 - return -EINVAL;
47 -
48 - rtc = rtc_device_register(pdev->name,
49 - &pdev->dev, &twl_rtc_ops, THIS_MODULE);
50 - if (IS_ERR(rtc)) {
51 - ret = PTR_ERR(rtc);
52 - dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
53 - PTR_ERR(rtc));
54 - goto out0;
55 -
56 - }
57 -
58 - platform_set_drvdata(pdev, rtc);
59 + goto out1;
61 ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
62 if (ret < 0)
63 @@ -454,14 +442,6 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
64 if (ret < 0)
65 goto out1;
67 - ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
68 - IRQF_TRIGGER_RISING,
69 - dev_name(&rtc->dev), rtc);
70 - if (ret < 0) {
71 - dev_err(&pdev->dev, "IRQ is not free.\n");
72 - goto out1;
73 - }
74 -
75 if (twl_class_is_6030()) {
76 twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
77 REG_INT_MSK_LINE_A);
78 @@ -472,28 +452,44 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
79 /* Check RTC module status, Enable if it is off */
80 ret = twl_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG);
81 if (ret < 0)
82 - goto out2;
83 + goto out1;
85 if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) {
86 dev_info(&pdev->dev, "Enabling TWL-RTC.\n");
87 rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M;
88 ret = twl_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG);
89 if (ret < 0)
90 - goto out2;
91 + goto out1;
92 }
94 /* init cached IRQ enable bits */
95 ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
96 if (ret < 0)
97 + goto out1;
98 +
99 + rtc = rtc_device_register(pdev->name,
100 + &pdev->dev, &twl_rtc_ops, THIS_MODULE);
101 + if (IS_ERR(rtc)) {
102 + ret = PTR_ERR(rtc);
103 + dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
104 + PTR_ERR(rtc));
105 + goto out1;
106 + }
107 +
108 + ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
109 + IRQF_TRIGGER_RISING,
110 + dev_name(&rtc->dev), rtc);
111 + if (ret < 0) {
112 + dev_err(&pdev->dev, "IRQ is not free.\n");
113 goto out2;
114 + }
116 - return ret;
117 + platform_set_drvdata(pdev, rtc);
118 + return 0;
120 out2:
121 - free_irq(irq, rtc);
122 -out1:
123 rtc_device_unregister(rtc);
124 -out0:
125 +out1:
126 return ret;
127 }