Skip to contentSkip to conversation

sandbox: Rework readX/writeX macros to be more like ARM

PATCH In review Tom Rini 1 participant 2 messages Oct 1, 2025 – Oct 11, 2025

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 sandbox: Rework readX/writeX macros to be more like ARM

The way that the current readX/writeX macros are implemented on sandbox means that when IO_TRACE is not enabled some code will throw up incorrect warnings due to how sandbox_{read,write} is implemented. We instead need to do the "uX __v; __v = sandbox..(..v); __v;" trick that ARM does.

---
 arch/sandbox/include/asm/io.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/sandbox/include/asm/io.h +8 -8
index cd3f5d6fd401..e3034b9c7032 100644
@@ -44,17 +44,17 @@ phys_addr_t map_to_sysmem(const void *ptr);
 unsigned long sandbox_read(const void *addr, enum sandboxio_size_t size);
 void sandbox_write(void *addr, unsigned int val, enum sandboxio_size_t size);
 
-#define readb(addr) sandbox_read((const void *)addr, SB_SIZE_8)
-#define readw(addr) sandbox_read((const void *)addr, SB_SIZE_16)
-#define readl(addr) sandbox_read((const void *)addr, SB_SIZE_32)
+#define readb(addr) ({ u8 __v = sandbox_read((const void *)addr, SB_SIZE_8); __v; })
+#define readw(addr) ({ u16 __v = sandbox_read((const void *)addr, SB_SIZE_16); __v; })
+#define readl(addr) ({ u32 __v = sandbox_read((const void *)addr, SB_SIZE_32); __v; })
 #ifdef CONFIG_64BIT
-#define readq(addr) sandbox_read((const void *)addr, SB_SIZE_64)
+#define readq(addr) ({ u64 __v = sandbox_read((const void *)addr, SB_SIZE_64); __v; })
 #endif
-#define writeb(v, addr) sandbox_write((void *)addr, v, SB_SIZE_8)
-#define writew(v, addr) sandbox_write((void *)addr, v, SB_SIZE_16)
-#define writel(v, addr) sandbox_write((void *)addr, v, SB_SIZE_32)
+#define writeb(v, addr) ({ u8 __v = v; sandbox_write((void *)addr, __v, SB_SIZE_8); __v; })
+#define writew(v, addr) ({ u16 __v = v; sandbox_write((void *)addr, __v, SB_SIZE_16); __v; })
+#define writel(v, addr) ({ u32 __v = v; sandbox_write((void *)addr, __v, SB_SIZE_32); __v; })
 #ifdef CONFIG_64BIT
-#define writeq(v, addr) sandbox_write((void *)addr, v, SB_SIZE_64)
+#define writeq(v, addr) ({ u64 __v = v; sandbox_write((void *)addr, __v, SB_SIZE_64); __v; })
 #endif
 
 #define readb_relaxed			readb
Signature · 1 line
2.43.0
author
#1 lore raw
Quoted 8 lines · Tom Rini

The way that the current readX/writeX macros are implemented on sandbox means that when IO_TRACE is not enabled some code will throw up incorrect warnings due to how sandbox_{read,write} is implemented. We instead need to do the "uX __v; __v = sandbox..(..v); __v;" trick that ARM does.

[...]

Applied to u-boot/master, thanks!

[1/1] sandbox: Rework readX/writeX macros to be more like ARM

      commit: b30155c08e95550296668766bfd7d3da27c970fe
Signature · 1 line
Tom