Skip to content

Commit

Permalink
Bug in mm/thrash.c function grab_swap_token()
Browse files Browse the repository at this point in the history
Following bug was uncovered by compiling with '-W' flag:

  CC      mm/thrash.o
mm/thrash.c: In function �grab_swap_token�:
mm/thrash.c:52: warning: comparison of unsigned expression < 0 is always false

Variable token_priority is unsigned, so decrementing first and then
checking the result does not work; fixed by reversing the test, patch
attached (compile tested only).

I am not sure if likely() makes much sense in this new situation, but
I'll let somebody else to make a decision on that.

Signed-off-by: Mika Kukkonen <[email protected]>
Cc: Rik van Riel <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Mika Kukkonen authored and Linus Torvalds committed May 11, 2007
1 parent 069f11f commit 7faaa5f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions mm/thrash.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ void grab_swap_token(void)
if (current_interval < current->mm->last_interval)
current->mm->token_priority++;
else {
current->mm->token_priority--;
if (unlikely(current->mm->token_priority < 0))
current->mm->token_priority = 0;
if (likely(current->mm->token_priority > 0))
current->mm->token_priority--;
}
/* Check if we deserve the token */
if (current->mm->token_priority >
Expand Down

0 comments on commit 7faaa5f

Please sign in to comment.