]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ratelimit: Warn if ->interval or ->burst are negative
authorPetr Mladek <pmladek@suse.com>
Thu, 24 Apr 2025 18:19:13 +0000 (11:19 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 8 May 2025 23:13:27 +0000 (16:13 -0700)
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/20250423115409.3425-1-spasswolf@web.de/
Signed-off-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
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>
lib/ratelimit.c

index ab8472edeb1d2d49590499be759674511b6c5732..6a5cb0541301368868e1f987acc50f9e57434f43 100644 (file)
@@ -40,6 +40,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
         * says always limit.
         */
        if (interval <= 0 || burst <= 0) {
+               WARN_ONCE(interval < 0 || burst < 0, "Negative interval (%d) or burst (%d): Uninitialized ratelimit_state structure?\n", interval, burst);
                ret = interval == 0 || burst > 0;
                if (!(READ_ONCE(rs->flags) & RATELIMIT_INITIALIZED) || (!interval && !burst) ||
                    !raw_spin_trylock_irqsave(&rs->lock, flags)) {