Commit c728b9c8 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

ipc: simplify semtimedop/semctl_main() common error path handling



With various straight RCU lock/unlock movements, one common exit path
pattern had become

	rcu_read_unlock();
	goto out_wakeup;

and in fact there were no cases where we wanted to exit to out_wakeup
_without_ releasing the RCU read lock.

So replace that pattern with "goto out_rcu_wakeup", and remove the old
out_wakeup.

Acked-by: default avatarDavidlohr Bueso <davidlohr.bueso@hp.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 321310ce
Loading
Loading
Loading
Loading
+14 −27
Original line number Original line Diff line number Diff line
@@ -1077,17 +1077,12 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
	nsems = sma->sem_nsems;
	nsems = sma->sem_nsems;


	err = -EACCES;
	err = -EACCES;
	if (ipcperms(ns, &sma->sem_perm,
	if (ipcperms(ns, &sma->sem_perm, cmd == SETALL ? S_IWUGO : S_IRUGO))
			cmd == SETALL ? S_IWUGO : S_IRUGO)) {
		goto out_rcu_wakeup;
		rcu_read_unlock();
		goto out_wakeup;
	}


	err = security_sem_semctl(sma, cmd);
	err = security_sem_semctl(sma, cmd);
	if (err) {
	if (err)
		rcu_read_unlock();
		goto out_rcu_wakeup;
		goto out_wakeup;
	}


	err = -EACCES;
	err = -EACCES;
	switch (cmd) {
	switch (cmd) {
@@ -1188,10 +1183,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
	/* GETVAL, GETPID, GETNCTN, GETZCNT: fall-through */
	/* GETVAL, GETPID, GETNCTN, GETZCNT: fall-through */
	}
	}
	err = -EINVAL;
	err = -EINVAL;
	if (semnum < 0 || semnum >= nsems) {
	if (semnum < 0 || semnum >= nsems)
		rcu_read_unlock();
		goto out_rcu_wakeup;
		goto out_wakeup;
	}


	sem_lock(sma, NULL, -1);
	sem_lock(sma, NULL, -1);
	curr = &sma->sem_base[semnum];
	curr = &sma->sem_base[semnum];
@@ -1213,8 +1206,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,


out_unlock:
out_unlock:
	sem_unlock(sma, -1);
	sem_unlock(sma, -1);
out_rcu_wakeup:
	rcu_read_unlock();
	rcu_read_unlock();
out_wakeup:
	wake_up_sem_queue_do(&tasks);
	wake_up_sem_queue_do(&tasks);
out_free:
out_free:
	if(sem_io != fast_sem_io)
	if(sem_io != fast_sem_io)
@@ -1585,22 +1578,16 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
	}
	}


	error = -EFBIG;
	error = -EFBIG;
	if (max >= sma->sem_nsems) {
	if (max >= sma->sem_nsems)
		rcu_read_unlock();
		goto out_rcu_wakeup;
		goto out_wakeup;
	}


	error = -EACCES;
	error = -EACCES;
	if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO)) {
	if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO))
		rcu_read_unlock();
		goto out_rcu_wakeup;
		goto out_wakeup;
	}


	error = security_sem_semop(sma, sops, nsops, alter);
	error = security_sem_semop(sma, sops, nsops, alter);
	if (error) {
	if (error)
		rcu_read_unlock();
		goto out_rcu_wakeup;
		goto out_wakeup;
	}


	/*
	/*
	 * semid identifiers are not unique - find_alloc_undo may have
	 * semid identifiers are not unique - find_alloc_undo may have
@@ -1718,8 +1705,8 @@ sleep_again:


out_unlock_free:
out_unlock_free:
	sem_unlock(sma, locknum);
	sem_unlock(sma, locknum);
out_rcu_wakeup:
	rcu_read_unlock();
	rcu_read_unlock();
out_wakeup:
	wake_up_sem_queue_do(&tasks);
	wake_up_sem_queue_do(&tasks);
out_free:
out_free:
	if(sops != fast_sops)
	if(sops != fast_sops)