From: Shaohua Li Date: Wed, 21 Mar 2012 23:34:17 +0000 (-0700) Subject: swap: don't do discard if no discard option added X-Git-Tag: v3.2.19~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07fb30fa5b317e65a6953471886b7fd04e1acb51;p=thirdparty%2Fkernel%2Fstable.git swap: don't do discard if no discard option added commit 052b1987faca3606109d88d96bce124851f7c4c2 upstream. When swapon() was not passed the SWAP_FLAG_DISCARD option, sys_swapon() will still perform a discard operation. This can cause problems if discard is slow or buggy. Reverse the order of the check so that a discard operation is performed only if the sys_swapon() caller is attempting to enable discard. Signed-off-by: Shaohua Li Reported-by: Holger Kiehl Tested-by: Holger Kiehl Cc: Hugh Dickins Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings --- diff --git a/mm/swapfile.c b/mm/swapfile.c index 2015a1e42dc0f..d3955f2745e53 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2102,7 +2102,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) p->flags |= SWP_SOLIDSTATE; p->cluster_next = 1 + (random32() % p->highest_bit); } - if (discard_swap(p) == 0 && (swap_flags & SWAP_FLAG_DISCARD)) + if ((swap_flags & SWAP_FLAG_DISCARD) && discard_swap(p) == 0) p->flags |= SWP_DISCARDABLE; }