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>] [day] [month] [year] [list]
Message-Id: <20240719075013.6600-1-henrybear327@gmail.com>
Date: Fri, 19 Jul 2024 09:50:13 +0200
From: Chun-Hung Tseng <henrybear327@...il.com>
To: luc.vanoostenryck@...il.com,
	arnd@...db.de,
	keescook@...omium.org,
	rostedt@...dmis.org,
	linux-sparse@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: Chun-Hung Tseng <henrybear327@...il.com>,
	Jim Huang <jserv@...s.ncku.edu.tw>
Subject: [PATCH] compiler.h: Improve __branch_check__ by using __UNIQUE_ID()

This commit replaced two hard-to-distinguish variables ______r and
______f to improve code readability and reduce variable name shadowing
issue.

______r is renamed by leveraging __UNIQUE_ID(branch_check) in
___branch_check__, and callers of the affected macros are adjusted.

__UNIQUE_ID(branch_check) will generate unique variable names during
compilation, which eliminates the need for ______r. This avoids the
variable name shadowing issue, or at least makes those wishing to cause
shadowing problems work much harder to do so.

______f in ftrace_likely_data struct is renamed using
__UNIQUE_ID(branch_check_data), following the same rationale above.

The same idea is used for the commit 589a9785ee3a ("min/max: remove sparse
warnings when they're nested"), and commit 24ba53017e18 ("rcu: Replace
________p1 and _________p1 with __UNIQUE_ID(rcu)").

Signed-off-by: Chun-Hung Tseng <henrybear327@...il.com>
Signed-off-by: Jim Huang <jserv@...s.ncku.edu.tw>
---
 include/linux/compiler.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 8c252e073bd8..b95e0990d52f 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -19,20 +19,20 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 #define likely_notrace(x)	__builtin_expect(!!(x), 1)
 #define unlikely_notrace(x)	__builtin_expect(!!(x), 0)
 
-#define __branch_check__(x, expect, is_constant) ({			\
-			long ______r;					\
+#define __branch_check__(x, local, local_data, expect, is_constant) ({	\
+			long local;					\
 			static struct ftrace_likely_data		\
 				__aligned(4)				\
 				__section("_ftrace_annotated_branch")	\
-				______f = {				\
+				local_data = {				\
 				.data.func = __func__,			\
 				.data.file = __FILE__,			\
 				.data.line = __LINE__,			\
 			};						\
-			______r = __builtin_expect(!!(x), expect);	\
-			ftrace_likely_update(&______f, ______r,		\
+			local = __builtin_expect(!!(x), expect);	\
+			ftrace_likely_update(&local_data, local,	\
 					     expect, is_constant);	\
-			______r;					\
+			local;						\
 		})
 
 /*
@@ -41,10 +41,14 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
  * written by Daniel Walker.
  */
 # ifndef likely
-#  define likely(x)	(__branch_check__(x, 1, __builtin_constant_p(x)))
+#  define likely(x)	(__branch_check__(x, __UNIQUE_ID(branch_check), \
+			__UNIQUE_ID(branch_check_data), 1,		\
+			__builtin_constant_p(x)))
 # endif
 # ifndef unlikely
-#  define unlikely(x)	(__branch_check__(x, 0, __builtin_constant_p(x)))
+#  define unlikely(x)	(__branch_check__(x, __UNIQUE_ID(branch_check), \
+			__UNIQUE_ID(branch_check_data), 0,		\
+			__builtin_constant_p(x)))
 # endif
 
 #ifdef CONFIG_PROFILE_ALL_BRANCHES
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ