Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1468156 > unrolled thread

[RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long

Started byNicolai Stange <nicstange@gmail.com>
First post2016-08-23 01:40 +0200
Last post2016-08-27 17:30 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long Nicolai Stange <nicstange@gmail.com> - 2016-08-23 01:40 +0200
    Re: [RFC v4 14/22] clockevents: clockevents_program_event(): turn  clc into unsigned long Thomas Gleixner <tglx@linutronix.de> - 2016-08-25 15:30 +0200
      Re: [RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long Nicolai Stange <nicstange@gmail.com> - 2016-08-27 17:30 +0200

#1468156 — [RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long

FromNicolai Stange <nicstange@gmail.com>
Date2016-08-23 01:40 +0200
Subject[RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long
Message-ID<s96YV-4v1-9@gated-at.bofh.it>
Right now, being of type unsigned long long, the clc local variable in
clockevents_program_event() is unnecessarily wide as it gets cast to
unsigned long anyway.

Degrade clc's type to unsigned long and remove the now superfluous casts.

Signed-off-by: Nicolai Stange <nicstange@gmail.com>
---
 kernel/time/clockevents.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index 7832050..8fddb67 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -311,7 +311,7 @@ static int clockevents_program_min_delta(struct clock_event_device *dev)
 int clockevents_program_event(struct clock_event_device *dev, ktime_t expires,
 			      bool force)
 {
-	unsigned long long clc;
+	unsigned long clc;
 	int64_t delta;
 	int rc;
 
@@ -337,11 +337,12 @@ int clockevents_program_event(struct clock_event_device *dev, ktime_t expires,
 	if (delta <= 0)
 		return force ? clockevents_program_min_delta(dev) : -ETIME;
 
-	clc = ((unsigned long long) delta * dev->mult) >> dev->shift;
-	clc = min_t(unsigned long, clc, dev->max_delta_ticks);
-	clc = max_t(unsigned long, clc, dev->min_delta_ticks_adjusted);
+	clc = (unsigned long)(((unsigned long long)delta *
+					dev->mult) >> dev->shift);
+	clc = min(clc, dev->max_delta_ticks);
+	clc = max(clc, dev->min_delta_ticks_adjusted);
 
-	rc = dev->set_next_event((unsigned long) clc, dev);
+	rc = dev->set_next_event(clc, dev);
 
 	return (rc && force) ? clockevents_program_min_delta(dev) : rc;
 }
-- 
2.9.2

[toc] | [next] | [standalone]


#1470144 — Re: [RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long

FromThomas Gleixner <tglx@linutronix.de>
Date2016-08-25 15:30 +0200
SubjectRe: [RFC v4 14/22] clockevents: clockevents_program_event(): turn clc into unsigned long
Message-ID<sa2Tf-1tU-29@gated-at.bofh.it>
In reply to#1468156
On Tue, 23 Aug 2016, Nicolai Stange wrote:

> Right now, being of type unsigned long long, the clc local variable in
> clockevents_program_event() is unnecessarily wide as it gets cast to
> unsigned long anyway.

Congrats! You just broke 32bit systems. When delta is sufficiently large then
the mult overflows....
 
Thanks,

	tglx

[toc] | [prev] | [next] | [standalone]


#1471204

FromNicolai Stange <nicstange@gmail.com>
Date2016-08-27 17:30 +0200
Message-ID<saNIu-6dz-23@gated-at.bofh.it>
In reply to#1470144
Thomas Gleixner <tglx@linutronix.de> writes:

> On Tue, 23 Aug 2016, Nicolai Stange wrote:
>
>> Right now, being of type unsigned long long, the clc local variable in
>> clockevents_program_event() is unnecessarily wide as it gets cast to
>> unsigned long anyway.
>
> Congrats! You just broke 32bit systems. When delta is sufficiently large then
> the mult overflows....

The 32bit breakage has been introduced in [13/22] ("clockevents: check a
programmed delta's bounds in terms of cycles") already -- please see my
reply there.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web