aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mm/swapfile.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index aafcf3611b31..71b42ec55b78 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2088,7 +2088,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
p->swap_file = swap_file;
mapping = swap_file->f_mapping;
- inode = mapping->host;
for (i = 0; i < nr_swapfiles; i++) {
struct swap_info_struct *q = swap_info[i];
@@ -2101,6 +2100,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
}
}
+ inode = mapping->host;
+ /* If S_ISREG(inode->i_mode) will do mutex_lock(&inode->i_mutex); */
error = claim_swapfile(p, inode);
if (unlikely(error))
goto bad_swap;
@@ -2187,8 +2188,10 @@ bad_swap:
spin_unlock(&swap_lock);
vfree(swap_map);
if (swap_file) {
- if (inode && S_ISREG(inode->i_mode))
+ if (inode && S_ISREG(inode->i_mode)) {
mutex_unlock(&inode->i_mutex);
+ inode = NULL;
+ }
filp_close(swap_file, NULL);
}
out: