Skip to content

Commit 248e735

Browse files
Davidlohr Buesotorvalds
authored andcommitted
ipc/sem: do not call wake_sem_queue_do() prematurely ... 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/1474225896-10066-2-git-send-email-dave@stgolabs.net Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Cc: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7a5c8b5 commit 248e735

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

‎ipc/sem.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,16 +1887,22 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
18871887
}
18881888

18891889
error = -EFBIG;
1890-
if (max >= sma->sem_nsems)
1891-
goto out_rcu_wakeup;
1890+
if (max >= sma->sem_nsems) {
1891+
rcu_read_unlock();
1892+
goto out_free;
1893+
}
18921894

18931895
error = -EACCES;
1894-
if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO))
1895-
goto out_rcu_wakeup;
1896+
if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO)) {
1897+
rcu_read_unlock();
1898+
goto out_free;
1899+
}
18961900

18971901
error = security_sem_semop(sma, sops, nsops, alter);
1898-
if (error)
1899-
goto out_rcu_wakeup;
1902+
if (error) {
1903+
rcu_read_unlock();
1904+
goto out_free;
1905+
}
19001906

19011907
error = -EIDRM;
19021908
locknum = sem_lock(sma, sops, nsops);
@@ -2039,7 +2045,6 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
20392045

20402046
out_unlock_free:
20412047
sem_unlock(sma, locknum);
2042-
out_rcu_wakeup:
20432048
rcu_read_unlock();
20442049
wake_up_sem_queue_do(&tasks);
20452050
out_free:

0 commit comments

Comments
 (0)