Commit 7cbf3192 authored by Omar Sandoval's avatar Omar Sandoval Committed by Linus Torvalds
Browse files

mm: fix nr_rotate_swap leak in swapon() error case

If swapon() fails after incrementing nr_rotate_swap, we don't decrement
it and thus effectively leak it.  Make sure we decrement it if we
incremented it.

Fixes: 81a0298b

 ("mm, swap: don't use VMA based swap readahead if HDD is used as swap")
Signed-off-by: default avatarOmar Sandoval <>
Reviewed-by: default avatarRik van Riel <>
Reviewed-by: default avatar"Huang, Ying" <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 62d18ecf
......@@ -3112,6 +3112,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
unsigned long *frontswap_map = NULL;
struct page *page = NULL;
struct inode *inode = NULL;
bool inced_nr_rotate_swap = false;
if (swap_flags & ~SWAP_FLAGS_VALID)
return -EINVAL;
......@@ -3215,8 +3216,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
cluster = per_cpu_ptr(p->percpu_cluster, cpu);
} else
} else {
inced_nr_rotate_swap = true;
error = swap_cgroup_swapon(p->type, maxpages);
if (error)
......@@ -3307,6 +3310,8 @@ bad_swap:
if (inced_nr_rotate_swap)
if (swap_file) {
if (inode && S_ISREG(inode->i_mode)) {
Supports Markdown
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