Skip to contentSkip to conversation

hrtimer: fix an explicit cast in __ktime_divns()

PATCH Applied Wen Yang 2 participants 2 messages Jan 30, 2020 – Mar 4, 2020 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 hrtimer: fix an explicit cast in __ktime_divns()

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.

---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
index d8b62f93fc8d..57e543860660 100644
@@ -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);
Signature · 1 line
2.23.0
merge bot Applied
#1 lore raw

[tip: timers/core] hrtimer: Cast explicitely to u32t in __ktime_divns()

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

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 <[email protected]>
AuthorDate:    Thu, 30 Jan 2020 21:08:51 +08:00
Committer:     Thomas Gleixner <[email protected]>
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.

---
 kernel/time/hrtimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/hrtimer.c +1 -1
index 3a609e7..d74fdcd 100644
@@ -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);