Skip to content

Commit a940d14

Browse files
pmladekpaulmckrcu
authored andcommitted
ratelimit: Warn if ->interval or ->burst are negative
Currently, ___ratelimit() treats a negative ->interval or ->burst as if it was zero, but this is an accident of the current implementation. Therefore, splat in this case, which might have the benefit of detecting use of uninitialized ratelimit_state structures on the one hand or easing addition of new features on the other. Link: https://lore.kernel.org/all/fbe93a52-365e-47fe-93a4-44a44547d601@paulmck-laptop/ Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Petr Mladek <[email protected]> Signed-off-by: Paul E. McKenney <[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 96d3660 commit a940d14

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/ratelimit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
4040
* says always limit.
4141
*/
4242
if (interval <= 0 || burst <= 0) {
43+
WARN_ONCE(interval < 0 || burst < 0, "Negative interval (%d) or burst (%d): Uninitialized ratelimit_state structure?\n", interval, burst);
4344
ret = interval == 0 || burst > 0;
4445
if (!(READ_ONCE(rs->flags) & RATELIMIT_INITIALIZED) || (!interval && !burst) ||
4546
!raw_spin_trylock_irqsave(&rs->lock, flags)) {

0 commit comments

Comments
 (0)