Commit 4b2cce99 authored by Paul E. McKenney's avatar Paul E. McKenney
Browse files

ratelimit: Use nolock_ret restructuring to collapse common case code

Now that unlock_ret releases the lock, then falls into nolock_ret, which
handles ->missed based on the value of ret, the common-case lock-held
code can be collapsed into a single "if" statement with a single-statement
"then" clause.

Yes, we could go further and just assign the "if" condition to ret,
but in the immortal words of MSDOS, "Are you sure?".

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: default avatarPaul E. McKenney <paulmck@kernel.org>
Reviewed-by: default avatarPetr 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>
parent 743a1942
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -88,17 +88,10 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
			}
		}
	}
	if (burst) {
		int n_left = atomic_read(&rs->rs_n_left);

		/* The burst might have been taken by a parallel call. */

		if (n_left > 0) {
			n_left = atomic_dec_return(&rs->rs_n_left);
			if (n_left >= 0)
	/* Note that the burst might be taken by a parallel call. */
	if (burst && atomic_read(&rs->rs_n_left) > 0 && atomic_dec_return(&rs->rs_n_left) >= 0)
		ret = 1;
		}
	}

unlock_ret:
	raw_spin_unlock_irqrestore(&rs->lock, flags);