]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ratelimit: Use nolock_ret label to save a couple of lines of code
authorPaul E. McKenney <paulmck@kernel.org>
Thu, 24 Apr 2025 19:06:43 +0000 (12:06 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Thu, 8 May 2025 23:13:27 +0000 (16:13 -0700)
Create a nolock_ret label in order to start consolidating the unlocked
return paths that conditionally invoke ratelimit_state_inc_miss().

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>
lib/ratelimit.c

index 7c6e864306db26822e706d1afd17a62109dcc838..e7101a79c697393d824fe000e7b1f31c3e3a893f 100644 (file)
@@ -43,11 +43,8 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
                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)) {
-                       if (!ret)
-                               ratelimit_state_inc_miss(rs);
-                       return ret;
-               }
+                   !raw_spin_trylock_irqsave(&rs->lock, flags))
+                       goto nolock_ret;
 
                /* Force re-initialization once re-enabled. */
                rs->flags &= ~RATELIMIT_INITIALIZED;
@@ -116,6 +113,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
 unlock_ret:
        raw_spin_unlock_irqrestore(&rs->lock, flags);
 
+nolock_ret:
        if (!ret)
                ratelimit_state_inc_miss(rs);