Skip to content

Commit 73737b8

Browse files
vdsaotorvalds
authored andcommitted
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 <[email protected]> Cc: Alessandro Zummo <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 22ea71d commit 73737b8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/rtc/rtc-r9701.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,20 @@ static int __devinit r9701_probe(struct spi_device *spi)
125125
unsigned char tmp;
126126
int res;
127127

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+
128135
rtc = rtc_device_register("r9701",
129136
&spi->dev, &r9701_rtc_ops, THIS_MODULE);
130137
if (IS_ERR(rtc))
131138
return PTR_ERR(rtc);
132139

133140
dev_set_drvdata(&spi->dev, rtc);
134141

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-
142142
return 0;
143143
}
144144

0 commit comments

Comments
 (0)