Skip to content

Commit 084a990

Browse files
committed
ratelimit: Allow zero ->burst to disable ratelimiting
If ->interval is zero, then rate-limiting will be disabled. Alternatively, if interval is greater than zero and ->burst is zero, then rate-limiting will be applied unconditionally. The point of this distinction is to handle current users that pass zero-initialized ratelimit_state structures to ___ratelimit(), and in such cases the ->lock field will be uninitialized. Acquiring ->lock in this case is clearly not a strategy to win. Therefore, make this classification be lockless. Note that although negative ->interval and ->burst happen to be treated as if they were zero, this is an accident of the current implementation. The semantics of negative values for these fields is subject to change without notice. Especially given that Bert Karwatzki determined that no current calls to ___ratelimit() ever have negative values for these fields. This commit replaces an earlier buggy versions. Link: https://lore.kernel.org/all/fbe93a52-365e-47fe-93a4-44a44547d601@paulmck-laptop/ Link: https://lore.kernel.org/all/[email protected]/ Reported-by: Bert Karwatzki <[email protected]> Reported-by: "Aithal, Srikanth" <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reported-by: Mark Brown <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Paul E. McKenney <[email protected]> Tested-by: "Aithal, Srikanth" <[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 cf8cfa8 commit 084a990

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/ratelimit.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
3535
unsigned long flags;
3636
int ret;
3737

38-
if (!interval)
39-
return 1;
38+
if (interval <= 0 || burst <= 0) {
39+
ret = interval == 0 || burst > 0;
40+
if (!ret)
41+
ratelimit_state_inc_miss(rs);
42+
return ret;
43+
}
4044

4145
/*
4246
* If we contend on this state's lock then just check if

0 commit comments

Comments
 (0)