mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] time: Avoid signed overflow in timekeeping_delta_to_ns()
@ 2016-11-14 19:42 Chris Metcalf
  2016-11-14 19:54 ` John Stultz
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Chris Metcalf @ 2016-11-14 19:42 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner, Laurent Vivier, David Gibson,
	Christopher S . Hall, linux-kernel
  Cc: Chris Metcalf

This bugfix was originally made in commit 35a4933a8959 ("time:
Avoid signed overflow in timekeeping_get_ns()").  When the code was
refactored in commit 6bd58f09e1d8 ("time: Add cycles to nanoseconds
translation") the signed overflow fix was lost.  Re-introduce it.

Signed-off-by: Chris Metcalf <cmetcalf@mellanox.com>
---
I happened to be looking for an unrelated fix, found this code,
realized the tip code didn't match the fixed code, and
backtracked to where it had gone away.

 kernel/time/timekeeping.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 37dec7e3db43..57926bc7b7f3 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -304,8 +304,7 @@ static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
 {
 	s64 nsec;
 
-	nsec = delta * tkr->mult + tkr->xtime_nsec;
-	nsec >>= tkr->shift;
+	nsec = (delta * tkr->mult + tkr->xtime_nsec) >> tkr->shift;
 
 	/* If arch requires, add in get_arch_timeoffset() */
 	return nsec + arch_gettimeoffset();
-- 
2.7.2

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

end of thread, other threads:[~2016-11-16 21:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-14 19:42 [PATCH] time: Avoid signed overflow in timekeeping_delta_to_ns() Chris Metcalf
2016-11-14 19:54 ` John Stultz
2016-11-15 21:53   ` Thomas Gleixner
2016-11-15 22:03     ` John Stultz
2016-11-16  1:10       ` John Stultz
2016-11-16 21:20   ` [PATCH v2] " Chris Metcalf
2016-11-15  0:56 ` [PATCH] " David Gibson
2016-11-15  7:58 ` Laurent Vivier

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

all inboxes | Powered by JetHome®