public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
@ 2015-12-04  0:12 Sasha Levin
  2015-12-04  0:21 ` kbuild test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sasha Levin @ 2015-12-04  0:12 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: rtc-linux, linux-kernel, Sasha Levin

At some point after humans go extinct and robots cotrol the world, dividing
he time64_t by 86400 to extract the days will overflow a 32bit integer,
leading to incorrect conversion into rtc_time in rtc_time64_to_tm().

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 drivers/rtc/rtc-lib.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index e6bfb9c..459cd4d 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -54,11 +54,11 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
 {
 	unsigned int month, year;
 	unsigned long secs;
-	int days;
+	time64_t days;
 
 	/* time must be positive */
 	days = div_s64(time, 86400);
-	secs = time - (unsigned int) days * 86400;
+	secs = time - days * 86400;
 
 	/* day of the week, 1970-01-01 was a Thursday */
 	tm->tm_wday = (days + 4) % 7;
-- 
1.7.10.4


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

end of thread, other threads:[~2015-12-04  2:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-04  0:12 [PATCH] rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Sasha Levin
2015-12-04  0:21 ` kbuild test robot
2015-12-04  1:39 ` kbuild test robot
2015-12-04  1:41 ` kbuild test robot
2015-12-04  1:55 ` Alexandre Belloni
2015-12-04  2:06   ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox