Revert commit 6950d046eb6e ("rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ") and add a comment. As described in a previous commit 66e4f4a9cc38 ("rtc: cmos: Use spin_lock_irqsave() in cmos_interrupt()") from February 2020: cmos_interrupt() isn't always called from hardirq context, so we must use spin_lock_irqsave() & co. Indeed, cmos_interrupt() is called from cmos_check_wkalrm(), which is called from cmos_resume() - apparently not in an interrupt context. A later commit 6950d046eb6e ("rtc: cmos: Replace spin_lock_irqsave with spin_lock in hard IRQ") did not take account of this and changed spin_lock_irqsave() to spin_lock(). This may cause a deadlock as quoted in the body of commit 66e4f4a9cc38 ("rtc: cmos: Use spin_lock_irqsave() in cmos_interrupt()") mentioned earlier. Signed-off-by: Mateusz Jończyk <mat.jonczyk@xxxxx> Cc: Alessandro Zummo <a.zummo@xxxxxxxxxxxx> Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx> Cc: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx> Cc: Xiaofei Tan <tanxiaofei@xxxxxxxxxx> --- drivers/rtc/rtc-cmos.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index c24465f7bed4..508fba8746a1 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -741,10 +741,14 @@ static struct cmos_rtc cmos_rtc; static irqreturn_t cmos_interrupt(int irq, void *p) { + unsigned long flags; u8 irqstat; u8 rtc_control; - spin_lock(&rtc_lock); + /* cmos_interrupt() may be called from cmos_check_wkalrm() not in + * interrupt context, so using spin_lock_irqsave() is required + */ + spin_lock_irqsave(&rtc_lock, flags); /* When the HPET interrupt handler calls us, the interrupt * status is passed as arg1 instead of the irq number. But @@ -778,7 +782,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p) hpet_mask_rtc_irq_bit(RTC_AIE); CMOS_READ(RTC_INTR_FLAGS); } - spin_unlock(&rtc_lock); + spin_unlock_irqrestore(&rtc_lock, flags); if (is_intr(irqstat)) { rtc_update_irq(p, 1, irqstat); -- 2.25.1