diff options
author | Nicholas Piggin <npiggin@gmail.com> | 2023-05-13 21:31:34 +1000 |
---|---|---|
committer | Reza Arbab <arbab@linux.ibm.com> | 2023-06-06 13:32:12 -0500 |
commit | c6d9b3d454cfb077e32fe257d8d3dc3f6f78d10f (patch) | |
tree | c02ea3e80a122a3866bb834c8002e37b1e2061eb /core | |
parent | 17bbda085f3bc12dd94198706c7199f10e15fce9 (diff) | |
download | skiboot-c6d9b3d454cfb077e32fe257d8d3dc3f6f78d10f.zip skiboot-c6d9b3d454cfb077e32fe257d8d3dc3f6f78d10f.tar.gz skiboot-c6d9b3d454cfb077e32fe257d8d3dc3f6f78d10f.tar.bz2 |
mem_region: Add a local_free function
This allows memory to be allocated with local_alloc() to be freed.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/mem_region.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/mem_region.c b/core/mem_region.c index e78d0a9..0ed00f3 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -920,6 +920,40 @@ restart: return p; } +static struct mem_region *mem_to_region(void *mem) +{ + struct mem_region *region; + + list_for_each(®ions, region, list) { + if (mem < region_start(region)) + continue; + if (mem >= region_start(region) + region->len) + continue; + return region; + } + return NULL; +} + +void __local_free(void *mem, const char *location) +{ + struct mem_region *region; + + lock(&mem_region_lock); + + region = mem_to_region(mem); + if (!region) { + prerror("MEM: local_free mem=%p no matching region.\n", mem); + unlock(&mem_region_lock); + return; + } + + lock(®ion->free_list_lock); + mem_free(region, mem, location); + unlock(®ion->free_list_lock); + + unlock(&mem_region_lock); +} + struct mem_region *find_mem_region(const char *name) { struct mem_region *region; |