Skip to content

Commit 743a194

Browse files
committed
ratelimit: Use nolock_ret label to collapse lock-failure code
Now that we have a nolock_ret label that handles ->missed correctly based on the value of ret, we can eliminate a local variable and collapse several "if" statements on the lock-acquisition-failure code path. Link: https://lore.kernel.org/all/fbe93a52-365e-47fe-93a4-44a44547d601@paulmck-laptop/ Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Kuniyuki Iwashima <[email protected]> Cc: Mateusz Guzik <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: John Ogness <[email protected]> Cc: Sergey Senozhatsky <[email protected]>
1 parent a69114c commit 743a194

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/ratelimit.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,10 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
5858
* the current lock owner is just about to reset it.
5959
*/
6060
if (!raw_spin_trylock_irqsave(&rs->lock, flags)) {
61-
unsigned int rs_flags = READ_ONCE(rs->flags);
62-
63-
if (rs_flags & RATELIMIT_INITIALIZED && burst) {
64-
int n_left = atomic_read(&rs->rs_n_left);
65-
66-
if (n_left <= 0)
67-
return 0;
68-
n_left = atomic_dec_return(&rs->rs_n_left);
69-
if (n_left >= 0)
70-
return 1;
71-
}
72-
73-
ratelimit_state_inc_miss(rs);
74-
return 0;
61+
if (READ_ONCE(rs->flags) & RATELIMIT_INITIALIZED && burst &&
62+
atomic_read(&rs->rs_n_left) > 0 && atomic_dec_return(&rs->rs_n_left) >= 0)
63+
ret = 1;
64+
goto nolock_ret;
7565
}
7666

7767
if (!(rs->flags & RATELIMIT_INITIALIZED)) {

0 commit comments

Comments
 (0)