aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAnatolij Gustschin <agust@denx.de>2012-03-05 17:59:16 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-05 18:49:43 -0500
commit73737b878767ef441d7cc34ebeeba01dd0a68dd6 (patch)
tree6f8bbc31654c7d3ee8551743e84a85a5d540dd5c /drivers/rtc
parent22ea71d7f49c3115e3a9ced5eac109fef26d3559 (diff)
drivers/rtc/rtc-r9701.c: fix crash in r9701_remove()
If probing the RTC didn't succeed due to failed RTC register access, the RTC device will be unregistered. Then, when removing the module r9701_remove() causes a kernel crash while trying to unregister a not registered RTC device. Fix this by doing RTC register access test before RTC device registration. Signed-off-by: Anatolij Gustschin <agust@denx.de> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-r9701.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 9beba49c3c5b..2853c2a6f10f 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -125,6 +125,13 @@ static int __devinit r9701_probe(struct spi_device *spi)
125 unsigned char tmp; 125 unsigned char tmp;
126 int res; 126 int res;
127 127
128 tmp = R100CNT;
129 res = read_regs(&spi->dev, &tmp, 1);
130 if (res || tmp != 0x20) {
131 dev_err(&spi->dev, "cannot read RTC register\n");
132 return -ENODEV;
133 }
134
128 rtc = rtc_device_register("r9701", 135 rtc = rtc_device_register("r9701",
129 &spi->dev, &r9701_rtc_ops, THIS_MODULE); 136 &spi->dev, &r9701_rtc_ops, THIS_MODULE);
130 if (IS_ERR(rtc)) 137 if (IS_ERR(rtc))
@@ -132,13 +139,6 @@ static int __devinit r9701_probe(struct spi_device *spi)
132 139
133 dev_set_drvdata(&spi->dev, rtc); 140 dev_set_drvdata(&spi->dev, rtc);
134 141
135 tmp = R100CNT;
136 res = read_regs(&spi->dev, &tmp, 1);
137 if (res || tmp != 0x20) {
138 rtc_device_unregister(rtc);
139 return res;
140 }
141
142 return 0; 142 return 0;
143} 143}
144 144