Nico Huber has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31945
Change subject: arch/x86/mmio: Avoid pointer aliasing in write8() ......................................................................
arch/x86/mmio: Avoid pointer aliasing in write8()
Don't literally dereference a pointer to `char`. Use array indexing instead to avoid aliasing rules. Otherwise, the compiler might treat any memory as clobbered.
Change-Id: I441c27e789ad92a8125c92837244474a26250c8a Signed-off-by: Nico Huber nico.h@gmx.de --- M src/arch/x86/include/arch/mmio.h 1 file changed, 9 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/45/31945/1
diff --git a/src/arch/x86/include/arch/mmio.h b/src/arch/x86/include/arch/mmio.h index f271a97..790b699 100644 --- a/src/arch/x86/include/arch/mmio.h +++ b/src/arch/x86/include/arch/mmio.h @@ -45,7 +45,15 @@ static __always_inline void write8(volatile void *addr, uint8_t value) { - *((volatile uint8_t *)(addr)) = value; + /* + * Don't literally dereference a pointer to `char`. Use array + * indexing instead to avoid aliasing rules. Otherwise, the + * compiler might treat any memory as clobbered. + */ + volatile struct { + uint8_t reg[1]; + } *const ref = addr; + ref->reg[0] = value; }
static __always_inline void write16(volatile void *addr,