summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@kernel.org>2025-04-24 22:00:10 +0300
committerPaul E. McKenney <paulmck@kernel.org>2025-05-09 02:13:27 +0300
commitf2d0ea0f086ae8811bb957ae2f781387557f80bd (patch)
tree2e053ba477c74fd41c294cae8227e2eae0836cbb /lib
parenta940d145cc381c8cde0d0f7f9faf282fbab89bfb (diff)
downloadlinux-f2d0ea0f086ae8811bb957ae2f781387557f80bd.tar.xz
ratelimit: Simplify common-case exit path
By making "ret" always be initialized, and moving the final call to ratelimit_state_inc_miss() out from under the lock, we save a goto and a couple lines of code. This also saves a couple of lines of code from the unconditional enable/disable slowpath. 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>
Diffstat (limited to 'lib')
-rw-r--r--lib/ratelimit.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/ratelimit.c b/lib/ratelimit.c
index 6a5cb0541301..7c6e864306db 100644
--- a/lib/ratelimit.c
+++ b/lib/ratelimit.c
@@ -33,7 +33,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
int interval = READ_ONCE(rs->interval);
int burst = READ_ONCE(rs->burst);
unsigned long flags;
- int ret;
+ int ret = 0;
/*
* Zero interval says never limit, otherwise, non-positive burst
@@ -51,8 +51,6 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
/* Force re-initialization once re-enabled. */
rs->flags &= ~RATELIMIT_INITIALIZED;
- if (!ret)
- ratelimit_state_inc_miss(rs);
goto unlock_ret;
}
@@ -110,19 +108,17 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
if (n_left > 0) {
n_left = atomic_dec_return(&rs->rs_n_left);
- if (n_left >= 0) {
+ if (n_left >= 0)
ret = 1;
- goto unlock_ret;
- }
}
}
- ratelimit_state_inc_miss(rs);
- ret = 0;
-
unlock_ret:
raw_spin_unlock_irqrestore(&rs->lock, flags);
+ if (!ret)
+ ratelimit_state_inc_miss(rs);
+
return ret;
}
EXPORT_SYMBOL(___ratelimit);