Skip to content

Commit 4b2cce9

Browse files
committed
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/[email protected]/ Signed-off-by: Paul E. McKenney <[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 743a194 commit 4b2cce9

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/ratelimit.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,10 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
8888
}
8989
}
9090
}
91-
if (burst) {
92-
int n_left = atomic_read(&rs->rs_n_left);
9391

94-
/* The burst might have been taken by a parallel call. */
95-
96-
if (n_left > 0) {
97-
n_left = atomic_dec_return(&rs->rs_n_left);
98-
if (n_left >= 0)
99-
ret = 1;
100-
}
101-
}
92+
/* Note that the burst might be taken by a parallel call. */
93+
if (burst && atomic_read(&rs->rs_n_left) > 0 && atomic_dec_return(&rs->rs_n_left) >= 0)
94+
ret = 1;
10295

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

0 commit comments

Comments
 (0)