Commit 7faaa5f0 authored by Mika Kukkonen's avatar Mika Kukkonen Committed by Linus Torvalds

Bug in mm/thrash.c function grab_swap_token()

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: default avatarMika Kukkonen <mikukkon@iki.fi>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 069f11f9
...@@ -48,9 +48,8 @@ void grab_swap_token(void) ...@@ -48,9 +48,8 @@ void grab_swap_token(void)
if (current_interval < current->mm->last_interval) if (current_interval < current->mm->last_interval)
current->mm->token_priority++; current->mm->token_priority++;
else { else {
if (likely(current->mm->token_priority > 0))
current->mm->token_priority--; current->mm->token_priority--;
if (unlikely(current->mm->token_priority < 0))
current->mm->token_priority = 0;
} }
/* Check if we deserve the token */ /* Check if we deserve the token */
if (current->mm->token_priority > if (current->mm->token_priority >
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment