Commit 53cbb2435f161f2a8b36af8f6d2c46dc59d0d757
Committed by
Linus Torvalds
1 parent
e8e6c2ec40
Exists in
master
and in
7 other branches
sys_swapon: separate swap_info allocation
Move the swap_info allocation to its own function. Only code movement, no functional changes. 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: 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>
Showing 1 changed file with 37 additions and 20 deletions Side-by-side Diff
mm/swapfile.c
... | ... | @@ -1844,33 +1844,15 @@ |
1844 | 1844 | late_initcall(max_swapfiles_check); |
1845 | 1845 | #endif |
1846 | 1846 | |
1847 | -SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | |
1847 | +static struct swap_info_struct *alloc_swap_info(void) | |
1848 | 1848 | { |
1849 | 1849 | struct swap_info_struct *p; |
1850 | - char *name = NULL; | |
1851 | - struct block_device *bdev = NULL; | |
1852 | - struct file *swap_file = NULL; | |
1853 | - struct address_space *mapping; | |
1854 | 1850 | unsigned int type; |
1855 | - int i, prev; | |
1856 | 1851 | int error; |
1857 | - union swap_header *swap_header; | |
1858 | - unsigned int nr_good_pages; | |
1859 | - int nr_extents = 0; | |
1860 | - sector_t span; | |
1861 | - unsigned long maxpages; | |
1862 | - unsigned long swapfilepages; | |
1863 | - unsigned char *swap_map = NULL; | |
1864 | - struct page *page = NULL; | |
1865 | - struct inode *inode = NULL; | |
1866 | - int did_down = 0; | |
1867 | 1852 | |
1868 | - if (!capable(CAP_SYS_ADMIN)) | |
1869 | - return -EPERM; | |
1870 | - | |
1871 | 1853 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
1872 | 1854 | if (!p) |
1873 | - return -ENOMEM; | |
1855 | + return ERR_PTR(-ENOMEM); | |
1874 | 1856 | |
1875 | 1857 | spin_lock(&swap_lock); |
1876 | 1858 | for (type = 0; type < nr_swapfiles; type++) { |
... | ... | @@ -1905,6 +1887,41 @@ |
1905 | 1887 | p->flags = SWP_USED; |
1906 | 1888 | p->next = -1; |
1907 | 1889 | spin_unlock(&swap_lock); |
1890 | + | |
1891 | + return p; | |
1892 | + | |
1893 | +out: | |
1894 | + return ERR_PTR(error); | |
1895 | +} | |
1896 | + | |
1897 | +SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | |
1898 | +{ | |
1899 | + struct swap_info_struct *p; | |
1900 | + char *name = NULL; | |
1901 | + struct block_device *bdev = NULL; | |
1902 | + struct file *swap_file = NULL; | |
1903 | + struct address_space *mapping; | |
1904 | + int i, prev; | |
1905 | + int error; | |
1906 | + union swap_header *swap_header; | |
1907 | + unsigned int nr_good_pages; | |
1908 | + int nr_extents = 0; | |
1909 | + sector_t span; | |
1910 | + unsigned long maxpages; | |
1911 | + unsigned long swapfilepages; | |
1912 | + unsigned char *swap_map = NULL; | |
1913 | + struct page *page = NULL; | |
1914 | + struct inode *inode = NULL; | |
1915 | + int did_down = 0; | |
1916 | + | |
1917 | + if (!capable(CAP_SYS_ADMIN)) | |
1918 | + return -EPERM; | |
1919 | + | |
1920 | + p = alloc_swap_info(); | |
1921 | + if (IS_ERR(p)) { | |
1922 | + error = PTR_ERR(p); | |
1923 | + goto out; | |
1924 | + } | |
1908 | 1925 | |
1909 | 1926 | name = getname(specialfile); |
1910 | 1927 | error = PTR_ERR(name); |