From: Min-Hsun Chang <chmh0624@gmail.com>
To: arnd@arndb.de, david.laight.linux@gmail.com
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
Min-Hsun Chang <chmh0624@gmail.com>
Subject: [PATCH v2] asm-generic: convert __set_fixmap_offset() to static inline
Date: Mon, 23 Mar 2026 14:02:15 +0800 [thread overview]
Message-ID: <20260323060228.21064-1-chmh0624@gmail.com> (raw)
In-Reply-To: <20260322144032.7353997c@pumpkin>
The current macro implementation of __set_fixmap_offset() uses a
hardcoded identifier `________addr` within a statement expression.
This can lead to variable shadowing and potential naming conflicts.
Furthermore, the macro expands its `idx` and `phys` arguments twice.
This double evaluation is dangerous if arguments with side effects
(e.g., i++) are passed to the macro.
Convert the macro to a static inline function as suggested by David.
This improves type safety, avoids shadowing, and ensures each
argument is evaluated exactly once.
Signed-off-by: Min-Hsun Chang <chmh0624@gmail.com>
---
Changes in v2:
- Convert the macro to a static inline function instead of just
renaming the local variable (suggested by David Laight).
- This addresses both variable shadowing and double evaluation
issues pointed out during v1 review.
- Link to v1: https://lore.kernel.org/all/20260307092119.20733-1-chmh0624@gmail.com/
---
include/asm-generic/fixmap.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/asm-generic/fixmap.h b/include/asm-generic/fixmap.h
index 29cab7947980..541b8db35af2 100644
--- a/include/asm-generic/fixmap.h
+++ b/include/asm-generic/fixmap.h
@@ -71,13 +71,13 @@ static inline unsigned long virt_to_fix(const unsigned long vaddr)
#endif
/* Return a pointer with offset calculated */
-#define __set_fixmap_offset(idx, phys, flags) \
-({ \
- unsigned long ________addr; \
- __set_fixmap(idx, phys, flags); \
- ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \
- ________addr; \
-})
+static inline unsigned long __set_fixmap_offset(unsigned int idx,
+ phys_addr_t phys,
+ pgprot_t flags)
+{
+ __set_fixmap(idx, phys, flags);
+ return fix_to_virt(idx) + (phys & (PAGE_SIZE - 1));
+}
#define set_fixmap_offset(idx, phys) \
__set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
--
2.43.0
prev parent reply other threads:[~2026-03-23 6:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 9:21 [PATCH] asm-generic: replace ________addr with __UNIQUE_ID(addr) Min-Hsun Chang
2026-03-22 13:20 ` Min-Hsun Chang
2026-03-22 14:40 ` David Laight
2026-03-23 6:02 ` Min-Hsun Chang [this message]
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=20260323060228.21064-1-chmh0624@gmail.com \
--to=chmh0624@gmail.com \
--cc=arnd@arndb.de \
--cc=david.laight.linux@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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