Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
From: Chun-Hung Tseng <henrybear327@gmail.com>
To: luc.vanoostenryck@gmail.com, linux-sparse@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Chun-Hung Tseng <henrybear327@gmail.com>,
	Jim Huang <jserv@ccns.ncku.edu.tw>
Subject: [PATCH] compiler.h: Improve __branch_check__ by using __UNIQUE_ID()
Date: Mon, 17 Jun 2024 14:29:35 +0200	[thread overview]
Message-ID: <20240617122934.2650453-1-henrybear327@gmail.com> (raw)

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@gmail.com>
Signed-off-by: Jim Huang <jserv@ccns.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


             reply	other threads:[~2024-06-17 12:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17 12:29 Chun-Hung Tseng [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-07-19  7:50 [PATCH] compiler.h: Improve __branch_check__ by using __UNIQUE_ID() Chun-Hung Tseng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240617122934.2650453-1-henrybear327@gmail.com \
    --to=henrybear327@gmail.com \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).