All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc-mc146818-lib: fix locking in mc146818_set_time
@ 2022-02-20  9:04 Mateusz Jończyk
  2022-03-08 16:38 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Jończyk @ 2022-02-20  9:04 UTC (permalink / raw)
  To: linux-rtc, linux-kernel
  Cc: Mateusz Jończyk, Alessandro Zummo, Alexandre Belloni,
	Thomas Gleixner, stable

In mc146818_set_time(), CMOS_READ(RTC_CONTROL) was performed without the
rtc_lock taken, which is required for CMOS accesses. Fix this.

Nothing in kernel modifies RTC_DM_BINARY, so a separate critical section
is allowed here.

Fixes: dcf257e92622 ("rtc: mc146818: Reduce spinlock section in mc146818_set_time()")
Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
---
 drivers/rtc/rtc-mc146818-lib.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
index ae9f131b43c0..562f99b664a2 100644
--- a/drivers/rtc/rtc-mc146818-lib.c
+++ b/drivers/rtc/rtc-mc146818-lib.c
@@ -232,8 +232,10 @@ int mc146818_set_time(struct rtc_time *time)
 	if (yrs >= 100)
 		yrs -= 100;
 
-	if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY)
-	    || RTC_ALWAYS_BCD) {
+	spin_lock_irqsave(&rtc_lock, flags);
+	save_control = CMOS_READ(RTC_CONTROL);
+	spin_unlock_irqrestore(&rtc_lock, flags);
+	if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
 		sec = bin2bcd(sec);
 		min = bin2bcd(min);
 		hrs = bin2bcd(hrs);

base-commit: 754e0b0e35608ed5206d6a67a791563c631cec07
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtc-mc146818-lib: fix locking in mc146818_set_time
  2022-02-20  9:04 [PATCH] rtc-mc146818-lib: fix locking in mc146818_set_time Mateusz Jończyk
@ 2022-03-08 16:38 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2022-03-08 16:38 UTC (permalink / raw)
  To: linux-kernel, Mateusz Jończyk, linux-rtc
  Cc: Alexandre Belloni, Thomas Gleixner, stable, Alessandro Zummo

On Sun, 20 Feb 2022 10:04:03 +0100, Mateusz Jończyk wrote:
> In mc146818_set_time(), CMOS_READ(RTC_CONTROL) was performed without the
> rtc_lock taken, which is required for CMOS accesses. Fix this.
> 
> Nothing in kernel modifies RTC_DM_BINARY, so a separate critical section
> is allowed here.
> 
> 
> [...]

Applied, thanks!

[1/1] rtc-mc146818-lib: fix locking in mc146818_set_time
      commit: c63cdb340a7e0bd3734f9f8e27f082a054b45887

Best regards,
-- 
Alexandre Belloni <alexandre.belloni@bootlin.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-08 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-20  9:04 [PATCH] rtc-mc146818-lib: fix locking in mc146818_set_time Mateusz Jończyk
2022-03-08 16:38 ` Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.