Commit 83ef99befc324803a54cf2a5fab5a322df3a99d6
Committed by
Linus Torvalds
1 parent
28b36bd741
Exists in
master
and in
7 other branches
sys_swapon: remove did_down variable
Since mutex_lock(&inode->i_mutex) is called just after setting inode, did_down is always equivalent to (inode && S_ISREG(inode->i_mode)). Use this fact to remove the did_down variable. Signed-off-by: Cesar Eduardo Barros <cesarb@cesarb.net> Tested-by: Eric B Munson <emunson@mgebm.net> Acked-by: Eric B Munson <emunson@mgebm.net> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 2 additions and 6 deletions Side-by-side Diff
mm/swapfile.c
... | ... | @@ -1907,7 +1907,6 @@ |
1907 | 1907 | unsigned char *swap_map = NULL; |
1908 | 1908 | struct page *page = NULL; |
1909 | 1909 | struct inode *inode = NULL; |
1910 | - int did_down = 0; | |
1911 | 1910 | |
1912 | 1911 | if (!capable(CAP_SYS_ADMIN)) |
1913 | 1912 | return -EPERM; |
... | ... | @@ -1962,7 +1961,6 @@ |
1962 | 1961 | } else if (S_ISREG(inode->i_mode)) { |
1963 | 1962 | p->bdev = inode->i_sb->s_bdev; |
1964 | 1963 | mutex_lock(&inode->i_mutex); |
1965 | - did_down = 1; | |
1966 | 1964 | if (IS_SWAPFILE(inode)) { |
1967 | 1965 | error = -EBUSY; |
1968 | 1966 | goto bad_swap; |
1969 | 1967 | |
... | ... | @@ -2154,10 +2152,8 @@ |
2154 | 2152 | spin_unlock(&swap_lock); |
2155 | 2153 | vfree(swap_map); |
2156 | 2154 | if (swap_file) { |
2157 | - if (did_down) { | |
2155 | + if (inode && S_ISREG(inode->i_mode)) | |
2158 | 2156 | mutex_unlock(&inode->i_mutex); |
2159 | - did_down = 0; | |
2160 | - } | |
2161 | 2157 | filp_close(swap_file, NULL); |
2162 | 2158 | } |
2163 | 2159 | out: |
... | ... | @@ -2167,7 +2163,7 @@ |
2167 | 2163 | } |
2168 | 2164 | if (name) |
2169 | 2165 | putname(name); |
2170 | - if (did_down) { | |
2166 | + if (inode && S_ISREG(inode->i_mode)) { | |
2171 | 2167 | if (!error) |
2172 | 2168 | inode->i_flags |= S_SWAPFILE; |
2173 | 2169 | mutex_unlock(&inode->i_mutex); |