public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: fix never executed code due to expression always false
@ 2005-04-14 23:49 Jesper Juhl
  2005-04-15  0:09 ` Nick Piggin
  0 siblings, 1 reply; 11+ messages in thread
From: Jesper Juhl @ 2005-04-14 23:49 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Robert Love, Linus Torvalds, linux-kernel


There are two expressions in kernel/sched.c that are always false since 
they test for <0 but the result of the expression is unsigned so they will 
never be less than zero. This patch implement the logic that I believe is 
intended without the signedness issue and without the nasty casts.
<disclaimer>patch is compile tested only</disclaimer>


Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
---

 sched.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

--- linux-2.6.12-rc2-mm3-orig/kernel/sched.c	2005-04-11 21:20:56.000000000 +0200
+++ linux-2.6.12-rc2-mm3/kernel/sched.c	2005-04-15 01:37:48.000000000 +0200
@@ -2697,9 +2697,10 @@ need_resched_nonpreemptible:
 	schedstat_inc(rq, sched_cnt);
 	now = sched_clock();
 	if (likely((long long)now - prev->timestamp < NS_MAX_SLEEP_AVG)) {
-		run_time = now - prev->timestamp;
-		if (unlikely((long long)now - prev->timestamp < 0))
+		if (unlikely(prev->timestamp > now))
 			run_time = 0;
+		else
+			run_time = now - prev->timestamp;
 	} else
 		run_time = NS_MAX_SLEEP_AVG;
 
@@ -2776,7 +2777,7 @@ go_idle:
 
 	if (!rt_task(next) && next->activated > 0) {
 		unsigned long long delta = now - next->timestamp;
-		if (unlikely((long long)now - next->timestamp < 0))
+		if (unlikely(next->timestamp > now))
 			delta = 0;
 
 		if (next->activated == 1)



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

end of thread, other threads:[~2005-04-16 13:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-14 23:49 [PATCH] sched: fix never executed code due to expression always false Jesper Juhl
2005-04-15  0:09 ` Nick Piggin
2005-04-15  0:14   ` Jesper Juhl
2005-04-15  0:13     ` Nick Piggin
2005-04-15  0:23       ` Jesper Juhl
2005-04-15  0:23         ` Nick Piggin
2005-04-15  2:32           ` Matt Mackall
2005-04-15  2:59         ` Herbert Xu
2005-04-15  3:25           ` Nick Piggin
2005-04-15  7:58         ` Ingo Molnar
2005-04-16 13:54           ` Jesper Juhl

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