rtc: mc146818: Detect and handle broken RTCs
authorThomas Gleixner <tglx@linutronix.de>
Tue, 26 Jan 2021 17:02:11 +0000 (18:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Dec 2022 10:31:55 +0000 (11:31 +0100)
commit3736972360fad22805e7e9d322387fd1ec0f48fc
treed62d31c00b5d9895940eee9cc7ddd8952a9d07d9
parent7c7075c88da4e108deb80257a3a5352ddf22ba4c
rtc: mc146818: Detect and handle broken RTCs

[ Upstream commit 211e5db19d15a721b2953ea54b8f26c2963720eb ]

The recent fix for handling the UIP bit unearthed another issue in the RTC
code. If the RTC is advertised but the readout is straight 0xFF because
it's not available, the old code just proceeded with crappy values, but the
new code hangs because it waits for the UIP bit to become low.

Add a sanity check in the RTC CMOS probe function which reads the RTC_VALID
register (Register D) which should have bit 0-6 cleared. If that's not the
case then fail to register the CMOS.

Add the same check to mc146818_get_time(), warn once when the condition
is true and invalidate the rtc_time data.

Reported-by: Mickaël Salaün <mic@digikod.net>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Mickaël Salaün <mic@linux.microsoft.com>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/87tur3fx7w.fsf@nanos.tec.linutronix.de
Stable-dep-of: cd17420ebea5 ("rtc: cmos: avoid UIP when writing alarm time")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/rtc/rtc-cmos.c
drivers/rtc/rtc-mc146818-lib.c