Skip to content

Commit

Permalink
drivers/rtc/rtc-r9701.c: fix crash in r9701_remove()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vdsao authored and torvalds committed Mar 5, 2012
1 parent 22ea71d commit 73737b8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions drivers/rtc/rtc-r9701.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ static int __devinit r9701_probe(struct spi_device *spi)
unsigned char tmp;
int res;

tmp = R100CNT;
res = read_regs(&spi->dev, &tmp, 1);
if (res || tmp != 0x20) {
dev_err(&spi->dev, "cannot read RTC register\n");
return -ENODEV;
}

rtc = rtc_device_register("r9701",
&spi->dev, &r9701_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc))
return PTR_ERR(rtc);

dev_set_drvdata(&spi->dev, rtc);

tmp = R100CNT;
res = read_regs(&spi->dev, &tmp, 1);
if (res || tmp != 0x20) {
rtc_device_unregister(rtc);
return res;
}

return 0;
}

Expand Down

0 comments on commit 73737b8

Please sign in to comment.