Merge tag 'exfat-for-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkin...
[linux-2.6-microblaze.git] / include / linux / jump_label.h
index 570831c..4e968eb 100644 (file)
@@ -224,9 +224,10 @@ extern bool arch_jump_label_transform_queue(struct jump_entry *entry,
                                            enum jump_label_type type);
 extern void arch_jump_label_transform_apply(void);
 extern int jump_label_text_reserved(void *start, void *end);
-extern void static_key_slow_inc(struct static_key *key);
+extern bool static_key_slow_inc(struct static_key *key);
+extern bool static_key_fast_inc_not_disabled(struct static_key *key);
 extern void static_key_slow_dec(struct static_key *key);
-extern void static_key_slow_inc_cpuslocked(struct static_key *key);
+extern bool static_key_slow_inc_cpuslocked(struct static_key *key);
 extern void static_key_slow_dec_cpuslocked(struct static_key *key);
 extern int static_key_count(struct static_key *key);
 extern void static_key_enable(struct static_key *key);
@@ -278,11 +279,23 @@ static __always_inline bool static_key_true(struct static_key *key)
        return false;
 }
 
-static inline void static_key_slow_inc(struct static_key *key)
+static inline bool static_key_fast_inc_not_disabled(struct static_key *key)
 {
+       int v;
+
        STATIC_KEY_CHECK_USE(key);
-       atomic_inc(&key->enabled);
+       /*
+        * Prevent key->enabled getting negative to follow the same semantics
+        * as for CONFIG_JUMP_LABEL=y, see kernel/jump_label.c comment.
+        */
+       v = atomic_read(&key->enabled);
+       do {
+               if (v < 0 || (v + 1) < 0)
+                       return false;
+       } while (!likely(atomic_try_cmpxchg(&key->enabled, &v, v + 1)));
+       return true;
 }
+#define static_key_slow_inc(key)       static_key_fast_inc_not_disabled(key)
 
 static inline void static_key_slow_dec(struct static_key *key)
 {