[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1474868736-22724-1-git-send-email-liavr@mellanox.com>
Date: Mon, 26 Sep 2016 08:45:36 +0300
From: Liav Rehana <liavr@...lanox.com>
To: <john.stultz@...aro.org>
CC: <tglx@...utronix.de>, <linux-kernel@...r.kernel.org>,
<eladkan@...lanox.com>, <noamca@...lanox.com>,
Liav Rehana <liavr@...lanox.com>
Subject: [PATCH] timekeeping: Change type of nsec variable to unsigned in its calculation.
From: Liav Rehana <liavr@...lanox.com>
During the calculation of the nsec variable in the inline function
timekeeping_delta_to_ns, it may undergo a sign extension if its msb
is set just before the shift. The sign extension may, in some cases,
gain it a value near the maximum value of the 64-bit range. This is
bad when it is later used in a division function, such as
__iter_div_u64_rem, where the amount of loops it will go through to
calculate the division will be too large.
The following commit fixes that chance of sign extension, while
maintaining the type of the nsec variable as signed for other
functions that use this variable, for possible legit negative
time intervals.
Signed-off-by: Liav Rehana <liavr@...lanox.com>
---
kernel/time/timekeeping.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 479d25c..f2c0067 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -299,10 +299,10 @@ u32 (*arch_gettimeoffset)(void) = default_arch_gettimeoffset;
static inline u32 arch_gettimeoffset(void) { return 0; }
#endif
-static inline s64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
+static inline u64 timekeeping_delta_to_ns(struct tk_read_base *tkr,
cycle_t delta)
{
- s64 nsec;
+ u64 nsec;
nsec = delta * tkr->mult + tkr->xtime_nsec;
nsec >>= tkr->shift;
--
1.7.1
Powered by blists - more mailing lists