lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <152261542576.30503.8474929957674990486.stgit@warthog.procyon.org.uk>
Date:   Sun, 01 Apr 2018 21:43:45 +0100
From:   David Howells <dhowells@...hat.com>
To:     linux-kernel@...r.kernel.org
Subject: [PATCH 35/45] C++: Fix static_branch_likely/unlikely()

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

Signed-off-by: David Howells <dhowells@...hat.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 */
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ