Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 695ef79

Browse files
KAGA-KOKOPeter Zijlstra
authored andcommitted
jump_label: Clarify condition in static_key_fast_inc_not_disabled()
The second part of if (v <= 0 || (v + 1) < 0) is not immediately obvious that it acts as overflow protection. Check explicitely for v == INT_MAX instead and add a proper comment how this is used at the call sites. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20240610124406.484973160@linutronix.de
1 parent 83ab38e commit 695ef79

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/jump_label.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ bool static_key_fast_inc_not_disabled(struct static_key *key)
132132
/*
133133
* Negative key->enabled has a special meaning: it sends
134134
* static_key_slow_inc/dec() down the slow path, and it is non-zero
135-
* so it counts as "enabled" in jump_label_update(). Note that
136-
* atomic_inc_unless_negative() checks >= 0, so roll our own.
135+
* so it counts as "enabled" in jump_label_update().
136+
*
137+
* The INT_MAX overflow condition is either used by the networking
138+
* code to reset or detected in the slow path of
139+
* static_key_slow_inc_cpuslocked().
137140
*/
138141
v = atomic_read(&key->enabled);
139142
do {
140-
if (v <= 0 || (v + 1) < 0)
143+
if (v <= 0 || v == INT_MAX)
141144
return false;
142145
} while (!likely(atomic_try_cmpxchg(&key->enabled, &v, v + 1)));
143146

0 commit comments

Comments
 (0)