Skip to content

Commit d7c5ed7

Browse files
andrealmeidKAGA-KOKO
authored andcommitted
futex: Remove needless goto's
As stated in the coding style documentation, "if there is no cleanup needed then just return directly", instead of jumping to a label and then returning. Remove such goto's and replace with a return statement. When there's a ternary operator on the return value, replace it with the result of the operation when it is logically possible to determine it by the control flow. Signed-off-by: André Almeida <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9180bd4 commit d7c5ed7

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

kernel/futex.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,13 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
16071607

16081608
ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, FUTEX_READ);
16091609
if (unlikely(ret != 0))
1610-
goto out;
1610+
return ret;
16111611

16121612
hb = hash_futex(&key);
16131613

16141614
/* Make sure we really have tasks to wakeup */
16151615
if (!hb_waiters_pending(hb))
1616-
goto out;
1616+
return ret;
16171617

16181618
spin_lock(&hb->lock);
16191619

@@ -1636,7 +1636,6 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
16361636

16371637
spin_unlock(&hb->lock);
16381638
wake_up_q(&wake_q);
1639-
out:
16401639
return ret;
16411640
}
16421641

@@ -1703,10 +1702,10 @@ futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2,
17031702
retry:
17041703
ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ);
17051704
if (unlikely(ret != 0))
1706-
goto out;
1705+
return ret;
17071706
ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, FUTEX_WRITE);
17081707
if (unlikely(ret != 0))
1709-
goto out;
1708+
return ret;
17101709

17111710
hb1 = hash_futex(&key1);
17121711
hb2 = hash_futex(&key2);
@@ -1724,13 +1723,13 @@ futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2,
17241723
* an MMU, but we might get them from range checking
17251724
*/
17261725
ret = op_ret;
1727-
goto out;
1726+
return ret;
17281727
}
17291728

17301729
if (op_ret == -EFAULT) {
17311730
ret = fault_in_user_writeable(uaddr2);
17321731
if (ret)
1733-
goto out;
1732+
return ret;
17341733
}
17351734

17361735
if (!(flags & FLAGS_SHARED)) {
@@ -1773,7 +1772,6 @@ futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2,
17731772
out_unlock:
17741773
double_unlock_hb(hb1, hb2);
17751774
wake_up_q(&wake_q);
1776-
out:
17771775
return ret;
17781776
}
17791777

@@ -1980,20 +1978,18 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
19801978
retry:
19811979
ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, FUTEX_READ);
19821980
if (unlikely(ret != 0))
1983-
goto out;
1981+
return ret;
19841982
ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2,
19851983
requeue_pi ? FUTEX_WRITE : FUTEX_READ);
19861984
if (unlikely(ret != 0))
1987-
goto out;
1985+
return ret;
19881986

19891987
/*
19901988
* The check above which compares uaddrs is not sufficient for
19911989
* shared futexes. We need to compare the keys:
19921990
*/
1993-
if (requeue_pi && match_futex(&key1, &key2)) {
1994-
ret = -EINVAL;
1995-
goto out;
1996-
}
1991+
if (requeue_pi && match_futex(&key1, &key2))
1992+
return -EINVAL;
19971993

19981994
hb1 = hash_futex(&key1);
19991995
hb2 = hash_futex(&key2);
@@ -2013,7 +2009,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
20132009

20142010
ret = get_user(curval, uaddr1);
20152011
if (ret)
2016-
goto out;
2012+
return ret;
20172013

20182014
if (!(flags & FLAGS_SHARED))
20192015
goto retry_private;
@@ -2079,7 +2075,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
20792075
ret = fault_in_user_writeable(uaddr2);
20802076
if (!ret)
20812077
goto retry;
2082-
goto out;
2078+
return ret;
20832079
case -EBUSY:
20842080
case -EAGAIN:
20852081
/*
@@ -2198,8 +2194,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
21982194
double_unlock_hb(hb1, hb2);
21992195
wake_up_q(&wake_q);
22002196
hb_waiters_dec(hb2);
2201-
2202-
out:
22032197
return ret ? ret : task_count;
22042198
}
22052199

@@ -2545,7 +2539,7 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked)
25452539
*/
25462540
if (q->pi_state->owner != current)
25472541
ret = fixup_pi_state_owner(uaddr, q, current);
2548-
goto out;
2542+
return ret ? ret : locked;
25492543
}
25502544

25512545
/*
@@ -2558,7 +2552,7 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked)
25582552
*/
25592553
if (q->pi_state->owner == current) {
25602554
ret = fixup_pi_state_owner(uaddr, q, NULL);
2561-
goto out;
2555+
return ret;
25622556
}
25632557

25642558
/*
@@ -2572,8 +2566,7 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked)
25722566
q->pi_state->owner);
25732567
}
25742568

2575-
out:
2576-
return ret ? ret : locked;
2569+
return ret;
25772570
}
25782571

25792572
/**
@@ -2670,7 +2663,7 @@ static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
26702663

26712664
ret = get_user(uval, uaddr);
26722665
if (ret)
2673-
goto out;
2666+
return ret;
26742667

26752668
if (!(flags & FLAGS_SHARED))
26762669
goto retry_private;
@@ -2683,7 +2676,6 @@ static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
26832676
ret = -EWOULDBLOCK;
26842677
}
26852678

2686-
out:
26872679
return ret;
26882680
}
26892681

0 commit comments

Comments
 (0)