]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
jump_label: Clarify condition in static_key_fast_inc_not_disabled()
authorThomas Gleixner <tglx@linutronix.de>
Mon, 10 Jun 2024 12:46:37 +0000 (14:46 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 11 Jun 2024 09:25:23 +0000 (11:25 +0200)
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
kernel/jump_label.c

index 1f05a19918f47998bf492d75da673ddf80274c5c..4d06ec2f3e074dc9ca11c942b8dfc658139447ad 100644 (file)
@@ -132,12 +132,15 @@ bool static_key_fast_inc_not_disabled(struct static_key *key)
        /*
         * Negative key->enabled has a special meaning: it sends
         * static_key_slow_inc/dec() down the slow path, and it is non-zero
-        * so it counts as "enabled" in jump_label_update().  Note that
-        * atomic_inc_unless_negative() checks >= 0, so roll our own.
+        * so it counts as "enabled" in jump_label_update().
+        *
+        * The INT_MAX overflow condition is either used by the networking
+        * code to reset or detected in the slow path of
+        * static_key_slow_inc_cpuslocked().
         */
        v = atomic_read(&key->enabled);
        do {
-               if (v <= 0 || (v + 1) < 0)
+               if (v <= 0 || v == INT_MAX)
                        return false;
        } while (!likely(atomic_try_cmpxchg(&key->enabled, &v, v + 1)));