linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hrtimer: fix an explicit cast in __ktime_divns()
@ 2020-01-30 13:08 Wen Yang
  2020-03-04  9:20 ` [tip: timers/core] hrtimer: Cast explicitely to u32t " tip-bot2 for Wen Yang
  0 siblings, 1 reply; 2+ messages in thread
From: Wen Yang @ 2020-01-30 13:08 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Wen Yang, linux-kernel

do_div() does a 64-by-32 division, while the divisor 'div' is
explicitly casted to unsigned long, thus 64-bit on 64-bit platforms.
In addition, the above lines also ensures that the divisor is less
than 2^32. Hence the proper cast type is u32.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index d8b62f93fc8d..57e543860660 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -311,7 +311,7 @@ s64 __ktime_divns(const ktime_t kt, s64 div)
 		div >>= 1;
 	}
 	tmp >>= sft;
-	do_div(tmp, (unsigned long) div);
+	do_div(tmp, (u32) div);
 	return dclc < 0 ? -tmp : tmp;
 }
 EXPORT_SYMBOL_GPL(__ktime_divns);
-- 
2.23.0


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

* [tip: timers/core] hrtimer: Cast explicitely to u32t in __ktime_divns()
  2020-01-30 13:08 [PATCH] hrtimer: fix an explicit cast in __ktime_divns() Wen Yang
@ 2020-03-04  9:20 ` tip-bot2 for Wen Yang
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Wen Yang @ 2020-03-04  9:20 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Wen Yang, Thomas Gleixner, x86, LKML

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     38f7b0b1316d435f38ec3f2bb078897b7a1cfdea
Gitweb:        https://git.kernel.org/tip/38f7b0b1316d435f38ec3f2bb078897b7a1cfdea
Author:        Wen Yang <wenyang@linux.alibaba.com>
AuthorDate:    Thu, 30 Jan 2020 21:08:51 +08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 04 Mar 2020 10:17:51 +01:00

hrtimer: Cast explicitely to u32t in __ktime_divns()

do_div() does a 64-by-32 division at least on 32bit platforms, while the
divisor 'div' is explicitly casted to unsigned long, thus 64-bit on 64-bit
platforms.

The code already ensures that the divisor is less than 2^32. Hence the
proper cast type is u32.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200130130851.29204-1-wenyang@linux.alibaba.com

---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 3a609e7..d74fdcd 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -311,7 +311,7 @@ s64 __ktime_divns(const ktime_t kt, s64 div)
 		div >>= 1;
 	}
 	tmp >>= sft;
-	do_div(tmp, (unsigned long) div);
+	do_div(tmp, (u32) div);
 	return dclc < 0 ? -tmp : tmp;
 }
 EXPORT_SYMBOL_GPL(__ktime_divns);

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

end of thread, other threads:[~2020-03-04  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-30 13:08 [PATCH] hrtimer: fix an explicit cast in __ktime_divns() Wen Yang
2020-03-04  9:20 ` [tip: timers/core] hrtimer: Cast explicitely to u32t " tip-bot2 for Wen Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).