[RFC,v5,11/16] core/mem_region.c: Implement local free
diff mbox series

Message ID 20200227204023.22125-12-grimm@linux.ibm.com
State New
Headers show
Series
  • Ultravisor support in skiboot
Related show

Checks

Context Check Description
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (82aed17a5468aff6b600ee1694a10a60f942c018)

Commit Message

Ryan Grimm Feb. 27, 2020, 8:40 p.m. UTC
Signed-off-by: Ryan Grimm <grimm@us.ibm.com>
---
 core/mem_region.c           | 32 ++++++++++++++++++++++++++++++++
 include/mem_region-malloc.h |  3 +++
 2 files changed, 35 insertions(+)

Patch
diff mbox series

diff --git a/core/mem_region.c b/core/mem_region.c
index eb48a1a1..6fe315bd 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -906,6 +906,38 @@  restart:
 	return p;
 }
 
+void __local_free(void *p, const char *location)
+{
+	struct mem_region *region;
+	struct alloc_hdr *hdr;
+
+	if (!p)
+		return;
+
+	lock(&mem_region_lock);
+
+	list_for_each(&regions, region, list) {
+		/* local_alloc doesn't use heap */
+		if (region == &skiboot_heap)
+			continue;
+
+		if (p >= region_start(region) &&
+		   (p < (region_start(region) + region->len))) {
+			hdr = p - sizeof(*hdr);
+
+			if (hdr->free)
+				bad_header(region, hdr, "re-freed", location);
+
+			lock(&region->free_list_lock);
+			make_free(region, (struct free_hdr *)hdr, location, false);
+			unlock(&region->free_list_lock);
+		}
+
+	}
+
+	unlock(&mem_region_lock);
+}
+
 struct mem_region *find_mem_region(const char *name)
 {
 	struct mem_region *region;
diff --git a/include/mem_region-malloc.h b/include/mem_region-malloc.h
index 4350c564..c1a6b886 100644
--- a/include/mem_region-malloc.h
+++ b/include/mem_region-malloc.h
@@ -28,4 +28,7 @@  void *__local_alloc(unsigned int chip, size_t size, size_t align,
 #define local_alloc(chip_id, size, align)	\
 	__local_alloc((chip_id), (size), (align), __location__)
 
+void __local_free(void *ptr, const char *location);
+#define local_free(ptr) __local_free(ptr, __location__);
+
 #endif /* __MEM_REGION_MALLOC_H */