[PATCH v2] asm-generic: convert __set_fixmap_offset() to static inline

From: Min-Hsun Chang

Date: Mon Mar 23 2026 - 02:07:03 EST


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@xxxxxxxxx>
---
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@xxxxxxxxx/
---
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