summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2021-02-04 17:29:02 +0000
committerPanwar Vijay Kumar <pvijayku@codeaurora.org>2021-09-28 11:29:26 +0530
commita436b73e9032cdc9731255d950bb524739db037e (patch)
tree574222259e36eedb571eb5ad6fdb6d8351ced685 /kernel
parent11b99dbe32215bd92e0d417dad927673988f36a6 (diff)
futex: Simplify fixup_pi_state_owner()
From: Thomas Gleixner <tglx@linutronix.de> [ Upstream commit f2dac39d93987f7de1e20b3988c8685523247ae2 ] Too many gotos already and an upcoming fix would make it even more unreadable. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: stable@vger.kernel.org Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Git-commit: 47e452fcf2f50645247aa0240ae26e0d14d6d3ad Git-repo: https://android.googlesource.com/kernel/common/ Change-Id: Idf8902712a59e0c830fe0582a5b97a2ca54e1320 Signed-off-by: pvijayku <pvijayku@codeaurora.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/futex.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index d40884af7121..8b67e66210c0 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2135,18 +2135,16 @@ static void unqueue_me_pi(struct futex_q *q)
spin_unlock(q->lock_ptr);
}
-static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
- struct task_struct *argowner)
+static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
+ struct task_struct *argowner)
{
struct futex_pi_state *pi_state = q->pi_state;
- u32 uval, uninitialized_var(curval), newval;
struct task_struct *oldowner, *newowner;
- u32 newtid;
- int ret;
-
- lockdep_assert_held(q->lock_ptr);
+ u32 uval, curval, newval, newtid;
+ int err = 0;
oldowner = pi_state->owner;
+
/* Owner died? */
if (!pi_state->owner)
newtid |= FUTEX_OWNER_DIED;
@@ -2187,7 +2185,7 @@ retry:
if (__rt_mutex_futex_trylock(&pi_state->pi_mutex)) {
/* We got the lock after all, nothing to fix. */
- return 0;
+ return 1;
}
/*
@@ -2202,7 +2200,7 @@ retry:
* We raced against a concurrent self; things are
* already fixed up. Nothing to do.
*/
- return 0;
+ return 1;
}
newowner = argowner;
}
@@ -2243,7 +2241,7 @@ retry:
handle_fault:
spin_unlock(q->lock_ptr);
- ret = fault_in_user_writeable(uaddr);
+ err = fault_in_user_writeable(uaddr);
spin_lock(q->lock_ptr);
@@ -2251,12 +2249,27 @@ handle_fault:
* Check if someone else fixed it for us:
*/
if (pi_state->owner != oldowner)
- return 0;
+ return argowner == current;
- if (ret)
- return ret;
+ /* Retry if err was -EAGAIN or the fault in succeeded */
+ if (!err)
+ goto retry;
- goto retry;
+ return err;
+}
+
+static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
+ struct task_struct *argowner)
+{
+ struct futex_pi_state *pi_state = q->pi_state;
+ int ret;
+
+ lockdep_assert_held(q->lock_ptr);
+
+ raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
+ ret = __fixup_pi_state_owner(uaddr, q, argowner);
+ raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
+ return ret;
}
static long futex_wait_restart(struct restart_block *restart);