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/20250423115409.3425-1-spasswolf@web.de/ Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Kuniyuki Iwashima <kuniyu@amazon.com> Cc: Mateusz Guzik <mjguzik@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: John Ogness <john.ogness@linutronix.de> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
1 parent a69114c commit 743a194

1 file changed

Lines changed: 4 additions & 14 deletions

File tree

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)