Skip to content

Commit abc4dd7

Browse files
KAGA-KOKOgregkh
authored andcommitted
futex: Simplify fixup_pi_state_owner()
commit f2dac39 upstream 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a597f12 commit abc4dd7

1 file changed

Lines changed: 26 additions & 27 deletions

File tree

‎kernel/futex.c‎

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,18 +2331,13 @@ static void unqueue_me_pi(struct futex_q *q)
23312331
spin_unlock(q->lock_ptr);
23322332
}
23332333

2334-
static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
2335-
struct task_struct *argowner)
2334+
static int __fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
2335+
struct task_struct *argowner)
23362336
{
23372337
struct futex_pi_state *pi_state = q->pi_state;
2338-
u32 uval, curval, newval;
23392338
struct task_struct *oldowner, *newowner;
2340-
u32 newtid;
2341-
int ret, err = 0;
2342-
2343-
lockdep_assert_held(q->lock_ptr);
2344-
2345-
raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
2339+
u32 uval, curval, newval, newtid;
2340+
int err = 0;
23462341

23472342
oldowner = pi_state->owner;
23482343

@@ -2376,14 +2371,12 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
23762371
* We raced against a concurrent self; things are
23772372
* already fixed up. Nothing to do.
23782373
*/
2379-
ret = 0;
2380-
goto out_unlock;
2374+
return 0;
23812375
}
23822376

23832377
if (__rt_mutex_futex_trylock(&pi_state->pi_mutex)) {
23842378
/* We got the lock. pi_state is correct. Tell caller. */
2385-
ret = 1;
2386-
goto out_unlock;
2379+
return 1;
23872380
}
23882381

23892382
/*
@@ -2410,8 +2403,7 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
24102403
* We raced against a concurrent self; things are
24112404
* already fixed up. Nothing to do.
24122405
*/
2413-
ret = 1;
2414-
goto out_unlock;
2406+
return 1;
24152407
}
24162408
newowner = argowner;
24172409
}
@@ -2442,7 +2434,6 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
24422434
* itself.
24432435
*/
24442436
pi_state_update_owner(pi_state, newowner);
2445-
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
24462437

24472438
return argowner == current;
24482439

@@ -2465,17 +2456,16 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
24652456

24662457
switch (err) {
24672458
case -EFAULT:
2468-
ret = fault_in_user_writeable(uaddr);
2459+
err = fault_in_user_writeable(uaddr);
24692460
break;
24702461

24712462
case -EAGAIN:
24722463
cond_resched();
2473-
ret = 0;
2464+
err = 0;
24742465
break;
24752466

24762467
default:
24772468
WARN_ON_ONCE(1);
2478-
ret = err;
24792469
break;
24802470
}
24812471

@@ -2485,17 +2475,26 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
24852475
/*
24862476
* Check if someone else fixed it for us:
24872477
*/
2488-
if (pi_state->owner != oldowner) {
2489-
ret = argowner == current;
2490-
goto out_unlock;
2491-
}
2478+
if (pi_state->owner != oldowner)
2479+
return argowner == current;
24922480

2493-
if (ret)
2494-
goto out_unlock;
2481+
/* Retry if err was -EAGAIN or the fault in succeeded */
2482+
if (!err)
2483+
goto retry;
24952484

2496-
goto retry;
2485+
return err;
2486+
}
24972487

2498-
out_unlock:
2488+
static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
2489+
struct task_struct *argowner)
2490+
{
2491+
struct futex_pi_state *pi_state = q->pi_state;
2492+
int ret;
2493+
2494+
lockdep_assert_held(q->lock_ptr);
2495+
2496+
raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
2497+
ret = __fixup_pi_state_owner(uaddr, q, argowner);
24992498
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
25002499
return ret;
25012500
}

0 commit comments

Comments
 (0)