提交 db09a6e4 编写于 作者: M Mateusz Jończyk 提交者: sanglipeng

rtc: mc146818-lib: fix locking in mc146818_set_time

stable inclusion
from stable-v5.10.159
commit 5c432383b6870c4c6e45ff9b02d89c39013f2e9b
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7NTXH

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=5c432383b6870c4c6e45ff9b02d89c39013f2e9b

--------------------------------

[ Upstream commit 811f5559 ]

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: dcf257e9 ("rtc: mc146818: Reduce spinlock section in mc146818_set_time()")
Signed-off-by: NMateusz 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
Signed-off-by: NAlexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220220090403.153928-1-mat.jonczyk@o2.plSigned-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: Nsanglipeng <sanglipeng1@jd.com>
上级 ff3c145e
...@@ -299,8 +299,10 @@ int mc146818_set_time(struct rtc_time *time) ...@@ -299,8 +299,10 @@ int mc146818_set_time(struct rtc_time *time)
if (yrs >= 100) if (yrs >= 100)
yrs -= 100; yrs -= 100;
if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) spin_lock_irqsave(&rtc_lock, flags);
|| RTC_ALWAYS_BCD) { save_control = CMOS_READ(RTC_CONTROL);
spin_unlock_irqrestore(&rtc_lock, flags);
if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
sec = bin2bcd(sec); sec = bin2bcd(sec);
min = bin2bcd(min); min = bin2bcd(min);
hrs = bin2bcd(hrs); hrs = bin2bcd(hrs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册