Merge remote-tracking branch 'sound-asoc/for-next'
[deliverable/linux.git] / include / linux / jump_label.h
index 68904469fba1b7492efda1b846edab53ed1f3b4e..a534c7f15a615520d802a78a82fe55d2af8e4cae 100644 (file)
@@ -21,6 +21,8 @@
  *
  * DEFINE_STATIC_KEY_TRUE(key);
  * DEFINE_STATIC_KEY_FALSE(key);
+ * DEFINE_STATIC_KEY_ARRAY_TRUE(keys, count);
+ * DEFINE_STATIC_KEY_ARRAY_FALSE(keys, count);
  * static_branch_likely()
  * static_branch_unlikely()
  *
@@ -76,7 +78,6 @@
 
 #include <linux/types.h>
 #include <linux/compiler.h>
-#include <linux/bug.h>
 
 extern bool static_key_initialized;
 
@@ -115,20 +116,8 @@ enum jump_label_type {
 
 struct module;
 
-#include <linux/atomic.h>
-
 #ifdef HAVE_JUMP_LABEL
 
-static inline int static_key_count(struct static_key *key)
-{
-       /*
-        * -1 means the first static_key_slow_inc() is in progress.
-        *  static_key_enabled() must return true, so return 1 here.
-        */
-       int n = atomic_read(&key->enabled);
-       return n >= 0 ? n : 1;
-}
-
 #define JUMP_TYPE_FALSE        0UL
 #define JUMP_TYPE_TRUE 1UL
 #define JUMP_TYPE_MASK 1UL
@@ -157,16 +146,29 @@ extern int jump_label_text_reserved(void *start, void *end);
 extern void static_key_slow_inc(struct static_key *key);
 extern void static_key_slow_dec(struct static_key *key);
 extern void jump_label_apply_nops(struct module *mod);
+extern int static_key_count(struct static_key *key);
+extern void static_key_enable(struct static_key *key);
+extern void static_key_disable(struct static_key *key);
 
+/*
+ * We should be using ATOMIC_INIT() for initializing .enabled, but
+ * the inclusion of atomic.h is problematic for inclusion of jump_label.h
+ * in 'low-level' headers. Thus, we are initializing .enabled with a
+ * raw value, but have added a BUILD_BUG_ON() to catch any issues in
+ * jump_label_init() see: kernel/jump_label.c.
+ */
 #define STATIC_KEY_INIT_TRUE                                   \
-       { .enabled = ATOMIC_INIT(1),                            \
+       { .enabled = { 1 },                                     \
          .entries = (void *)JUMP_TYPE_TRUE }
 #define STATIC_KEY_INIT_FALSE                                  \
-       { .enabled = ATOMIC_INIT(0),                            \
+       { .enabled = { 0 },                                     \
          .entries = (void *)JUMP_TYPE_FALSE }
 
 #else  /* !HAVE_JUMP_LABEL */
 
+#include <linux/atomic.h>
+#include <linux/bug.h>
+
 static inline int static_key_count(struct static_key *key)
 {
        return atomic_read(&key->enabled);
@@ -216,14 +218,6 @@ static inline int jump_label_apply_nops(struct module *mod)
        return 0;
 }
 
-#define STATIC_KEY_INIT_TRUE   { .enabled = ATOMIC_INIT(1) }
-#define STATIC_KEY_INIT_FALSE  { .enabled = ATOMIC_INIT(0) }
-
-#endif /* HAVE_JUMP_LABEL */
-
-#define STATIC_KEY_INIT STATIC_KEY_INIT_FALSE
-#define jump_label_enabled static_key_enabled
-
 static inline void static_key_enable(struct static_key *key)
 {
        int count = static_key_count(key);
@@ -244,6 +238,14 @@ static inline void static_key_disable(struct static_key *key)
                static_key_slow_dec(key);
 }
 
+#define STATIC_KEY_INIT_TRUE   { .enabled = ATOMIC_INIT(1) }
+#define STATIC_KEY_INIT_FALSE  { .enabled = ATOMIC_INIT(0) }
+
+#endif /* HAVE_JUMP_LABEL */
+
+#define STATIC_KEY_INIT STATIC_KEY_INIT_FALSE
+#define jump_label_enabled static_key_enabled
+
 /* -------------------------------------------------------------------------- */
 
 /*
@@ -270,6 +272,16 @@ struct static_key_false {
 #define DEFINE_STATIC_KEY_FALSE(name)  \
        struct static_key_false name = STATIC_KEY_FALSE_INIT
 
+#define DEFINE_STATIC_KEY_ARRAY_TRUE(name, count)              \
+       struct static_key_true name[count] = {                  \
+               [0 ... (count) - 1] = STATIC_KEY_TRUE_INIT,     \
+       }
+
+#define DEFINE_STATIC_KEY_ARRAY_FALSE(name, count)             \
+       struct static_key_false name[count] = {                 \
+               [0 ... (count) - 1] = STATIC_KEY_FALSE_INIT,    \
+       }
+
 extern bool ____wrong_branch_error(void);
 
 #define static_key_enabled(x)                                                  \
This page took 0.044953 seconds and 5 git commands to generate.