Fix static_branch_likely/unlikely() to use C++ function overloading to
simplify the source.

Signed-off-by: David Howells <dhowe...@redhat.com>
---

 include/linux/jump_label.h |   41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 2168cc6b8b30..25683b1764bf 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -387,29 +387,26 @@ extern bool ____wrong_branch_error(void);
  * See jump_label_type() / jump_label_init_type().
  */
 
-#define static_branch_likely(x)                                                
        \
-({                                                                             
\
-       bool branch;                                                            
\
-       if (__builtin_types_compatible_p(typeof(*x), struct static_key_true))   
\
-               branch = !arch_static_branch(&(x)->key, true);                  
\
-       else if (__builtin_types_compatible_p(typeof(*x), struct 
static_key_false)) \
-               branch = !arch_static_branch_jump(&(x)->key, true);             
\
-       else                                                                    
\
-               branch = ____wrong_branch_error();                              
\
-       likely(branch);                                                         
\
-})
 
-#define static_branch_unlikely(x)                                              
\
-({                                                                             
\
-       bool branch;                                                            
\
-       if (__builtin_types_compatible_p(typeof(*x), struct static_key_true))   
\
-               branch = arch_static_branch_jump(&(x)->key, false);             
\
-       else if (__builtin_types_compatible_p(typeof(*x), struct 
static_key_false)) \
-               branch = arch_static_branch(&(x)->key, false);                  
\
-       else                                                                    
\
-               branch = ____wrong_branch_error();                              
\
-       unlikely(branch);                                                       
\
-})
+static inline bool static_branch_likely(struct static_key_true *x)
+{
+       return likely(!arch_static_branch(&(x)->key, true));
+}
+
+static inline bool static_branch_likely(struct static_key_false *x)
+{
+       return likely(!arch_static_branch_jump(&(x)->key, true));
+}
+
+static inline bool static_branch_unlikely(struct static_key_true *x)
+{
+       return unlikely(!arch_static_branch_jump(&(x)->key, true));
+}
+
+static inline bool static_branch_unlikely(struct static_key_false *x)
+{
+       return unlikely(!arch_static_branch(&(x)->key, true));
+}
 
 #else /* !HAVE_JUMP_LABEL */
 

Reply via email to