From: Simon Glass Date: Sun, 1 Sep 2024 22:26:25 +0000 (-0600) Subject: sandbox: Unmap old tags X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-favicon.png?a=commitdiff_plain;h=e82baf0801f399266781303675b0f66cca2bc51f;p=u-boot.git sandbox: Unmap old tags So far unmapping has not been implemented. This means that if one test maps a pointer to an address with map_sysmem(), then a second test can use that same pointer, by mapping the address back to a pointer with map_to_sysmem(). This is not really desirable, even if it doesn't cause any problems at the moment. Implement unmapping, to clean this up. Signed-off-by: Simon Glass --- diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 8eb055d683..3e1c0dd583 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -185,12 +185,28 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) void unmap_physmem(const void *ptr, unsigned long flags) { + struct sandbox_mapmem_entry *mentry; + #ifdef CONFIG_PCI if (map_dev) { pci_unmap_physmem(ptr, map_len, map_dev); map_dev = NULL; } #endif + + /* If it is in emulated RAM, we didn't create a tag, so nothing to do */ + if (is_in_sandbox_mem(ptr)) + return; + + mentry = find_tag(ptr); + if (mentry) { + list_del(&mentry->sibling_node); + log_debug("Removed map from %p to %lx\n", ptr, + (ulong)mentry->tag); + free(mentry); + } else { + log_warning("Address not mapped: %p\n", ptr); + } } phys_addr_t map_to_sysmem(const void *ptr)