Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8e6c2ec authored by Cesar Eduardo Barros's avatar Cesar Eduardo Barros Committed by Linus Torvalds
Browse files

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: default avatarCesar Eduardo Barros <cesarb@cesarb.net>
Tested-by: default avatarEric B Munson <emunson@mgebm.net>
Acked-by: default avatarEric B Munson <emunson@mgebm.net>
Reviewed-by: default avatarPekka Enberg <penberg@kernel.org>
Reviewed-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujisu.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 80b0df12
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -1927,7 +1927,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
	for (i = 0; i < nr_swapfiles; i++) {
	for (i = 0; i < nr_swapfiles; i++) {
		struct swap_info_struct *q = swap_info[i];
		struct swap_info_struct *q = swap_info[i];


		if (i == type || !q->swap_file)
		if (q == p || !q->swap_file)
			continue;
			continue;
		if (mapping == q->swap_file->f_mapping)
		if (mapping == q->swap_file->f_mapping)
			goto bad_swap;
			goto bad_swap;
@@ -2062,7 +2062,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
		}
		}
	}
	}


	error = swap_cgroup_swapon(type, maxpages);
	error = swap_cgroup_swapon(p->type, maxpages);
	if (error)
	if (error)
		goto bad_swap;
		goto bad_swap;


@@ -2120,9 +2120,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
	}
	}
	p->next = i;
	p->next = i;
	if (prev < 0)
	if (prev < 0)
		swap_list.head = swap_list.next = type;
		swap_list.head = swap_list.next = p->type;
	else
	else
		swap_info[prev]->next = type;
		swap_info[prev]->next = p->type;
	spin_unlock(&swap_lock);
	spin_unlock(&swap_lock);
	mutex_unlock(&swapon_mutex);
	mutex_unlock(&swapon_mutex);
	atomic_inc(&proc_poll_event);
	atomic_inc(&proc_poll_event);
@@ -2136,7 +2136,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
		blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
		blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
	}
	}
	destroy_swap_extents(p);
	destroy_swap_extents(p);
	swap_cgroup_swapoff(type);
	swap_cgroup_swapoff(p->type);
bad_swap_2:
bad_swap_2:
	spin_lock(&swap_lock);
	spin_lock(&swap_lock);
	p->swap_file = NULL;
	p->swap_file = NULL;