aboutsummaryrefslogtreecommitdiffstats
path: root/mm/swapfile.c
diff options
context:
space:
mode:
authorCesar Eduardo Barros <cesarb@cesarb.net>2011-03-22 19:33:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-22 20:44:07 -0400
commit7de7fb6b3422e6d1dac00666a992834085e745dc (patch)
tree4dd93f9871c1ff05212652a1e4709414a4881f1d /mm/swapfile.c
parent83ef99befc324803a54cf2a5fab5a322df3a99d6 (diff)
sys_swapon: move setting of error nearer use
Move the setting of the error variable nearer the goto in a few places. Avoids calling PTR_ERR() if not IS_ERR() in two places, and makes the error condition more explicit in two other places. 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: Jesper Juhl <jj@chaosbits.net> Reviewed-by: Pekka Enberg <penberg@kernel.org> 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>
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r--mm/swapfile.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index b261e55e0b82..e4dc94996c58 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1916,14 +1916,14 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
1916 return PTR_ERR(p); 1916 return PTR_ERR(p);
1917 1917
1918 name = getname(specialfile); 1918 name = getname(specialfile);
1919 error = PTR_ERR(name);
1920 if (IS_ERR(name)) { 1919 if (IS_ERR(name)) {
1920 error = PTR_ERR(name);
1921 name = NULL; 1921 name = NULL;
1922 goto bad_swap_2; 1922 goto bad_swap_2;
1923 } 1923 }
1924 swap_file = filp_open(name, O_RDWR|O_LARGEFILE, 0); 1924 swap_file = filp_open(name, O_RDWR|O_LARGEFILE, 0);
1925 error = PTR_ERR(swap_file);
1926 if (IS_ERR(swap_file)) { 1925 if (IS_ERR(swap_file)) {
1926 error = PTR_ERR(swap_file);
1927 swap_file = NULL; 1927 swap_file = NULL;
1928 goto bad_swap_2; 1928 goto bad_swap_2;
1929 } 1929 }
@@ -1932,17 +1932,17 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
1932 mapping = swap_file->f_mapping; 1932 mapping = swap_file->f_mapping;
1933 inode = mapping->host; 1933 inode = mapping->host;
1934 1934
1935 error = -EBUSY;
1936 for (i = 0; i < nr_swapfiles; i++) { 1935 for (i = 0; i < nr_swapfiles; i++) {
1937 struct swap_info_struct *q = swap_info[i]; 1936 struct swap_info_struct *q = swap_info[i];
1938 1937
1939 if (q == p || !q->swap_file) 1938 if (q == p || !q->swap_file)
1940 continue; 1939 continue;
1941 if (mapping == q->swap_file->f_mapping) 1940 if (mapping == q->swap_file->f_mapping) {
1941 error = -EBUSY;
1942 goto bad_swap; 1942 goto bad_swap;
1943 }
1943 } 1944 }
1944 1945
1945 error = -EINVAL;
1946 if (S_ISBLK(inode->i_mode)) { 1946 if (S_ISBLK(inode->i_mode)) {
1947 bdev = bdgrab(I_BDEV(inode)); 1947 bdev = bdgrab(I_BDEV(inode));
1948 error = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, 1948 error = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL,
@@ -1966,6 +1966,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
1966 goto bad_swap; 1966 goto bad_swap;
1967 } 1967 }
1968 } else { 1968 } else {
1969 error = -EINVAL;
1969 goto bad_swap; 1970 goto bad_swap;
1970 } 1971 }
1971 1972