]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/rtc-fix-overflow-when-converting-time64_t-to-rtc_time.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / rtc-fix-overflow-when-converting-time64_t-to-rtc_time.patch
1 From 36d46cdb43efea74043e29e2a62b13e9aca31452 Mon Sep 17 00:00:00 2001
2 From: Baolin Wang <baolin.wang@linaro.org>
3 Date: Mon, 25 Dec 2017 19:10:37 +0800
4 Subject: rtc: Fix overflow when converting time64_t to rtc_time
5
6 From: Baolin Wang <baolin.wang@linaro.org>
7
8 commit 36d46cdb43efea74043e29e2a62b13e9aca31452 upstream.
9
10 If we convert one large time values to rtc_time, in the original formula
11 'days * 86400' can be overflowed in 'unsigned int' type to make the formula
12 get one incorrect remain seconds value. Thus we can use div_s64_rem()
13 function to avoid this situation.
14
15 Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
16 Acked-by: Arnd Bergmann <arnd@arndb.de>
17 Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
18 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20
21 ---
22 drivers/rtc/rtc-lib.c | 6 ++----
23 1 file changed, 2 insertions(+), 4 deletions(-)
24
25 --- a/drivers/rtc/rtc-lib.c
26 +++ b/drivers/rtc/rtc-lib.c
27 @@ -52,13 +52,11 @@ EXPORT_SYMBOL(rtc_year_days);
28 */
29 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
30 {
31 - unsigned int month, year;
32 - unsigned long secs;
33 + unsigned int month, year, secs;
34 int days;
35
36 /* time must be positive */
37 - days = div_s64(time, 86400);
38 - secs = time - (unsigned int) days * 86400;
39 + days = div_s64_rem(time, 86400, &secs);
40
41 /* day of the week, 1970-01-01 was a Thursday */
42 tm->tm_wday = (days + 4) % 7;