From: CJ Chen <[email protected]>

When it comes to this pattern: .valid.unaligned = false and
impl.unaligned = true, is effectlvely contradictory. The .valid
structure indicates that unaligned access should be rejected at
the access validation phase, yet .impl suggests the underlying
device implementation can handle unaligned operations. As a result,
the upper-layer code will never even reach the .impl logic.

Add an assertion that the MemoryRegionOps doesn't specify
this invalid combination.

Signed-off-by: CJ Chen <[email protected]>
Tested-by: CJ Chen <[email protected]>
Suggested-by: Peter Xu <[email protected]>
Acked-by: Tomoyuki Hirose <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
[PMM: tweaked commit message]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
Link: 
https://lore.kernel.org/r/[email protected]
Signed-off-by: Peter Xu <[email protected]>
---
 system/memory.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/system/memory.c b/system/memory.c
index 225bbe38c3..739ba11da6 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1573,6 +1573,7 @@ void memory_region_init_io(MemoryRegion *mr, Object 
*owner,
                            const MemoryRegionOps *ops, void *opaque,
                            const char *name, uint64_t size)
 {
+    g_assert(!ops || !(ops->impl.unaligned && !ops->valid.unaligned));
     memory_region_init(mr, owner, name, size);
     memory_region_set_ops(mr, ops, opaque);
 }
-- 
2.53.0


Reply via email to