Commit e8e6c2ec403ecfaa226857d8204344c98fe12b7b
Committed by
Linus Torvalds
1 parent
80b0df12b8
Exists in
master
and in
7 other branches
sys_swapon: do not depend on "type" after allocation
Within sys_swapon, after the swap_info entry has been allocated, we always have type == p->type and swap_info[type] == p. Use this fact to reduce the dependency on the "type" local variable within the function, as a preparation to move the allocation of the swap_info entry to a separate function. 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.fujisu.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 5 additions and 5 deletions Side-by-side Diff
mm/swapfile.c
... | ... | @@ -1927,7 +1927,7 @@ |
1927 | 1927 | for (i = 0; i < nr_swapfiles; i++) { |
1928 | 1928 | struct swap_info_struct *q = swap_info[i]; |
1929 | 1929 | |
1930 | - if (i == type || !q->swap_file) | |
1930 | + if (q == p || !q->swap_file) | |
1931 | 1931 | continue; |
1932 | 1932 | if (mapping == q->swap_file->f_mapping) |
1933 | 1933 | goto bad_swap; |
... | ... | @@ -2062,7 +2062,7 @@ |
2062 | 2062 | } |
2063 | 2063 | } |
2064 | 2064 | |
2065 | - error = swap_cgroup_swapon(type, maxpages); | |
2065 | + error = swap_cgroup_swapon(p->type, maxpages); | |
2066 | 2066 | if (error) |
2067 | 2067 | goto bad_swap; |
2068 | 2068 | |
2069 | 2069 | |
... | ... | @@ -2120,9 +2120,9 @@ |
2120 | 2120 | } |
2121 | 2121 | p->next = i; |
2122 | 2122 | if (prev < 0) |
2123 | - swap_list.head = swap_list.next = type; | |
2123 | + swap_list.head = swap_list.next = p->type; | |
2124 | 2124 | else |
2125 | - swap_info[prev]->next = type; | |
2125 | + swap_info[prev]->next = p->type; | |
2126 | 2126 | spin_unlock(&swap_lock); |
2127 | 2127 | mutex_unlock(&swapon_mutex); |
2128 | 2128 | atomic_inc(&proc_poll_event); |
... | ... | @@ -2136,7 +2136,7 @@ |
2136 | 2136 | blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); |
2137 | 2137 | } |
2138 | 2138 | destroy_swap_extents(p); |
2139 | - swap_cgroup_swapoff(type); | |
2139 | + swap_cgroup_swapoff(p->type); | |
2140 | 2140 | bad_swap_2: |
2141 | 2141 | spin_lock(&swap_lock); |
2142 | 2142 | p->swap_file = NULL; |