Patch "rtc: mc146818: Detect and handle broken RTCs" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    rtc: mc146818: Detect and handle broken RTCs

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     rtc-mc146818-detect-and-handle-broken-rtcs.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 9ef93cd13386ac610b618b84cd2cc715272b215e
Author: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Date:   Tue Jan 26 18:02:11 2021 +0100

    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@xxxxxxxxxxx>
    Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
    Tested-by: Mickaël Salaün <mic@xxxxxxxxxxxxxxxxxxx>
    Acked-by: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
    Link: https://lore.kernel.org/r/87tur3fx7w.fsf@xxxxxxxxxxxxxxxxxxxxxxx
    Stable-dep-of: cd17420ebea5 ("rtc: cmos: avoid UIP when writing alarm time")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 58c6382a2807..cce4b62ffdd0 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -808,6 +808,14 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 
 	spin_lock_irq(&rtc_lock);
 
+	/* Ensure that the RTC is accessible. Bit 0-6 must be 0! */
+	if ((CMOS_READ(RTC_VALID) & 0x7f) != 0) {
+		spin_unlock_irq(&rtc_lock);
+		dev_warn(dev, "not accessible\n");
+		retval = -ENXIO;
+		goto cleanup1;
+	}
+
 	if (!(flags & CMOS_RTC_FLAGS_NOFREQ)) {
 		/* force periodic irq to CMOS reset default of 1024Hz;
 		 *
diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
index 8364e4141670..7f01dc41271d 100644
--- a/drivers/rtc/rtc-mc146818-lib.c
+++ b/drivers/rtc/rtc-mc146818-lib.c
@@ -21,6 +21,13 @@ unsigned int mc146818_get_time(struct rtc_time *time)
 
 again:
 	spin_lock_irqsave(&rtc_lock, flags);
+	/* Ensure that the RTC is accessible. Bit 0-6 must be 0! */
+	if (WARN_ON_ONCE((CMOS_READ(RTC_VALID) & 0x7f) != 0)) {
+		spin_unlock_irqrestore(&rtc_lock, flags);
+		memset(time, 0xff, sizeof(*time));
+		return 0;
+	}
+
 	/*
 	 * Check whether there is an update in progress during which the
 	 * readout is unspecified. The maximum update time is ~2ms. Poll



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux