Skip to content

Commit 17b756d

Browse files
committed
Merge tag 'timers-urgent-2021-01-31' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer fix from Thomas Gleixner: "A fix for handling advertised, but non-existent 146818 RTCs correctly. With the recent UIP handling changes the time readout of non-existent RTCs hangs forever as the read returns always 0xFF which means the UIP bit is set. Sanity check the RTC before registering by checking the RTC_VALID register for correctness" * tag 'timers-urgent-2021-01-31' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: rtc: mc146818: Detect and handle broken RTCs
2 parents f7ea44c + 211e5db commit 17b756d

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/rtc/rtc-cmos.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,14 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
805805

806806
spin_lock_irq(&rtc_lock);
807807

808+
/* Ensure that the RTC is accessible. Bit 0-6 must be 0! */
809+
if ((CMOS_READ(RTC_VALID) & 0x7f) != 0) {
810+
spin_unlock_irq(&rtc_lock);
811+
dev_warn(dev, "not accessible\n");
812+
retval = -ENXIO;
813+
goto cleanup1;
814+
}
815+
808816
if (!(flags & CMOS_RTC_FLAGS_NOFREQ)) {
809817
/* force periodic irq to CMOS reset default of 1024Hz;
810818
*

drivers/rtc/rtc-mc146818-lib.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ unsigned int mc146818_get_time(struct rtc_time *time)
2121

2222
again:
2323
spin_lock_irqsave(&rtc_lock, flags);
24+
/* Ensure that the RTC is accessible. Bit 0-6 must be 0! */
25+
if (WARN_ON_ONCE((CMOS_READ(RTC_VALID) & 0x7f) != 0)) {
26+
spin_unlock_irqrestore(&rtc_lock, flags);
27+
memset(time, 0xff, sizeof(*time));
28+
return 0;
29+
}
30+
2431
/*
2532
* Check whether there is an update in progress during which the
2633
* readout is unspecified. The maximum update time is ~2ms. Poll

0 commit comments

Comments
 (0)