aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/jump_label.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 5c1dfb2a9e73..784304b222b3 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -69,6 +69,10 @@ struct static_key {
69 69
70# include <asm/jump_label.h> 70# include <asm/jump_label.h>
71# define HAVE_JUMP_LABEL 71# define HAVE_JUMP_LABEL
72#else
73struct static_key {
74 atomic_t enabled;
75};
72#endif /* CC_HAVE_ASM_GOTO && CONFIG_JUMP_LABEL */ 76#endif /* CC_HAVE_ASM_GOTO && CONFIG_JUMP_LABEL */
73 77
74enum jump_label_type { 78enum jump_label_type {
@@ -79,6 +83,12 @@ enum jump_label_type {
79struct module; 83struct module;
80 84
81#include <linux/atomic.h> 85#include <linux/atomic.h>
86
87static inline int static_key_count(struct static_key *key)
88{
89 return atomic_read(&key->enabled);
90}
91
82#ifdef HAVE_JUMP_LABEL 92#ifdef HAVE_JUMP_LABEL
83 93
84#define JUMP_LABEL_TYPE_FALSE_BRANCH 0UL 94#define JUMP_LABEL_TYPE_FALSE_BRANCH 0UL
@@ -134,10 +144,6 @@ extern void jump_label_apply_nops(struct module *mod);
134 144
135#else /* !HAVE_JUMP_LABEL */ 145#else /* !HAVE_JUMP_LABEL */
136 146
137struct static_key {
138 atomic_t enabled;
139};
140
141static __always_inline void jump_label_init(void) 147static __always_inline void jump_label_init(void)
142{ 148{
143 static_key_initialized = true; 149 static_key_initialized = true;
@@ -145,14 +151,14 @@ static __always_inline void jump_label_init(void)
145 151
146static __always_inline bool static_key_false(struct static_key *key) 152static __always_inline bool static_key_false(struct static_key *key)
147{ 153{
148 if (unlikely(atomic_read(&key->enabled) > 0)) 154 if (unlikely(static_key_count(key) > 0))
149 return true; 155 return true;
150 return false; 156 return false;
151} 157}
152 158
153static __always_inline bool static_key_true(struct static_key *key) 159static __always_inline bool static_key_true(struct static_key *key)
154{ 160{
155 if (likely(atomic_read(&key->enabled) > 0)) 161 if (likely(static_key_count(key) > 0))
156 return true; 162 return true;
157 return false; 163 return false;
158} 164}
@@ -194,7 +200,7 @@ static inline int jump_label_apply_nops(struct module *mod)
194 200
195static inline bool static_key_enabled(struct static_key *key) 201static inline bool static_key_enabled(struct static_key *key)
196{ 202{
197 return (atomic_read(&key->enabled) > 0); 203 return static_key_count(key) > 0;
198} 204}
199 205
200#endif /* _LINUX_JUMP_LABEL_H */ 206#endif /* _LINUX_JUMP_LABEL_H */