Skip to content

Commit

Permalink
ipc/sem: do not call wake_sem_queue_do() prematurely
Browse files Browse the repository at this point in the history
... as this call should obviously be paired with its _prepare()
counterpart. At least whenever possible, as there is no harm in
calling it bogusly as we do now in a few places. Immediate error
semop(2) paths that are far from ever having the task block can
be simplified and avoid a few unnecessary loads on their way out
of the call as it is not deeply nested.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Davidlohr Bueso <[email protected]>
Cc: Manfred Spraul <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and hnaz committed Dec 1, 2016
1 parent 41f1966 commit 07a62a5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1904,16 +1904,22 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
}

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

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

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

error = -EIDRM;
locknum = sem_lock(sma, sops, nsops);
Expand Down Expand Up @@ -2056,7 +2062,6 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,

out_unlock_free:
sem_unlock(sma, locknum);
out_rcu_wakeup:
rcu_read_unlock();
wake_up_sem_queue_do(&tasks);
out_free:
Expand Down

0 comments on commit 07a62a5

Please sign in to comment.