Skip to content

Commit 36d46cd

Browse files
wangbaolin719alexandrebelloni
authored andcommitted
rtc: Fix overflow when converting time64_t to rtc_time
If we convert one large time values to rtc_time, in the original formula 'days * 86400' can be overflowed in 'unsigned int' type to make the formula get one incorrect remain seconds value. Thus we can use div_s64_rem() function to avoid this situation. Signed-off-by: Baolin Wang <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 29a1f59 commit 36d46cd

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/rtc/rtc-lib.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ EXPORT_SYMBOL(rtc_year_days);
5252
*/
5353
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
5454
{
55-
unsigned int month, year;
56-
unsigned long secs;
55+
unsigned int month, year, secs;
5756
int days;
5857

5958
/* time must be positive */
60-
days = div_s64(time, 86400);
61-
secs = time - (unsigned int) days * 86400;
59+
days = div_s64_rem(time, 86400, &secs);
6260

6361
/* day of the week, 1970-01-01 was a Thursday */
6462
tm->tm_wday = (days + 4) % 7;

0 commit comments

Comments
 (0)