Skip to content

Commit f2d0ea0

Browse files
committed
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>
1 parent a940d14 commit f2d0ea0

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

lib/ratelimit.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
3333
int interval = READ_ONCE(rs->interval);
3434
int burst = READ_ONCE(rs->burst);
3535
unsigned long flags;
36-
int ret;
36+
int ret = 0;
3737

3838
/*
3939
* Zero interval says never limit, otherwise, non-positive burst
@@ -51,8 +51,6 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
5151

5252
/* Force re-initialization once re-enabled. */
5353
rs->flags &= ~RATELIMIT_INITIALIZED;
54-
if (!ret)
55-
ratelimit_state_inc_miss(rs);
5654
goto unlock_ret;
5755
}
5856

@@ -110,19 +108,17 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
110108

111109
if (n_left > 0) {
112110
n_left = atomic_dec_return(&rs->rs_n_left);
113-
if (n_left >= 0) {
111+
if (n_left >= 0)
114112
ret = 1;
115-
goto unlock_ret;
116-
}
117113
}
118114
}
119115

120-
ratelimit_state_inc_miss(rs);
121-
ret = 0;
122-
123116
unlock_ret:
124117
raw_spin_unlock_irqrestore(&rs->lock, flags);
125118

119+
if (!ret)
120+
ratelimit_state_inc_miss(rs);
121+
126122
return ret;
127123
}
128124
EXPORT_SYMBOL(___ratelimit);

0 commit comments

Comments
 (0)