Commit b5fa01a2 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

ipc/sem: simplify wait-wake loop

Instead of using the reverse goto, we can simplify the flow and make it
more language natural by just doing do-while instead.  One would hope
this is the standard way (or obviously just with a while bucle) that we
do wait/wakeup handling in the kernel.  The exact same logic is kept,
just more indented.

[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/1478708774-28826-2-git-send-email-dave@stgolabs.netSigned-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f150f02c
...@@ -1963,7 +1963,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, ...@@ -1963,7 +1963,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
sma->complex_count++; sma->complex_count++;
} }
sleep_again: do {
queue.status = -EINTR; queue.status = -EINTR;
queue.sleeper = current; queue.sleeper = current;
...@@ -1977,22 +1977,23 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, ...@@ -1977,22 +1977,23 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
schedule(); schedule();
/* /*
* fastpath: the semop has completed, either successfully or not, from * fastpath: the semop has completed, either successfully or
* the syscall pov, is quite irrelevant to us at this point; we're done. * not, from the syscall pov, is quite irrelevant to us at this
* point; we're done.
* *
* We _do_ care, nonetheless, about being awoken by a signal or * We _do_ care, nonetheless, about being awoken by a signal or
* spuriously. The queue.status is checked again in the slowpath (aka * spuriously. The queue.status is checked again in the
* after taking sem_lock), such that we can detect scenarios where we * slowpath (aka after taking sem_lock), such that we can detect
* were awakened externally, during the window between wake_q_add() and * scenarios where we were awakened externally, during the
* wake_up_q(). * window between wake_q_add() and wake_up_q().
*/ */
error = READ_ONCE(queue.status); error = READ_ONCE(queue.status);
if (error != -EINTR) { if (error != -EINTR) {
/* /*
* User space could assume that semop() is a memory barrier: * User space could assume that semop() is a memory
* Without the mb(), the cpu could speculatively read in user * barrier: Without the mb(), the cpu could
* space stale data that was overwritten by the previous owner * speculatively read in userspace stale data that was
* of the semaphore. * overwritten by the previous owner of the semaphore.
*/ */
smp_mb(); smp_mb();
goto out_free; goto out_free;
...@@ -2022,12 +2023,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, ...@@ -2022,12 +2023,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
*/ */
if (timeout && jiffies_left == 0) if (timeout && jiffies_left == 0)
error = -EAGAIN; error = -EAGAIN;
} while (error == -EINTR && !signal_pending(current)); /* spurious */
/*
* If the wakeup was spurious, just retry.
*/
if (error == -EINTR && !signal_pending(current))
goto sleep_again;
unlink_queue(sma, &queue); unlink_queue(sma, &queue);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment