]>
Commit | Line | Data |
---|---|---|
eeebef1c GKH |
1 | From 454f47ff464325223129b9b5b8d0b61946ec704d Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= <mat.jonczyk@o2.pl> | |
3 | Date: Fri, 10 Dec 2021 21:01:23 +0100 | |
4 | Subject: rtc: cmos: take rtc_lock while reading from CMOS | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | From: Mateusz Jończyk <mat.jonczyk@o2.pl> | |
10 | ||
11 | commit 454f47ff464325223129b9b5b8d0b61946ec704d upstream. | |
12 | ||
13 | Reading from the CMOS involves writing to the index register and then | |
14 | reading from the data register. Therefore access to the CMOS has to be | |
15 | serialized with rtc_lock. This invocation of CMOS_READ was not | |
16 | serialized, which could cause trouble when other code is accessing CMOS | |
17 | at the same time. | |
18 | ||
19 | Use spin_lock_irq() like the rest of the function. | |
20 | ||
21 | Nothing in kernel modifies the RTC_DM_BINARY bit, so there could be a | |
22 | separate pair of spin_lock_irq() / spin_unlock_irq() before doing the | |
23 | math. | |
24 | ||
25 | Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl> | |
26 | Reviewed-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org> | |
27 | Cc: Alessandro Zummo <a.zummo@towertech.it> | |
28 | Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> | |
29 | Cc: stable@vger.kernel.org | |
30 | Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> | |
31 | Link: https://lore.kernel.org/r/20211210200131.153887-2-mat.jonczyk@o2.pl | |
32 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
33 | --- | |
34 | drivers/rtc/rtc-cmos.c | 3 +++ | |
35 | 1 file changed, 3 insertions(+) | |
36 | ||
37 | --- a/drivers/rtc/rtc-cmos.c | |
38 | +++ b/drivers/rtc/rtc-cmos.c | |
39 | @@ -343,7 +343,10 @@ static int cmos_set_alarm(struct device | |
40 | min = t->time.tm_min; | |
41 | sec = t->time.tm_sec; | |
42 | ||
43 | + spin_lock_irq(&rtc_lock); | |
44 | rtc_control = CMOS_READ(RTC_CONTROL); | |
45 | + spin_unlock_irq(&rtc_lock); | |
46 | + | |
47 | if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { | |
48 | /* Writing 0xff means "don't care" or "match all". */ | |
49 | mon = (mon <= 12) ? bin2bcd(mon) : 0xff; |