[Skiboot] [PATCH v2 13/16] include/mem_region-malloc: Define calloc for CCAN Heap

Jordan Niethe jniethe5 at gmail.com
Tue Apr 2 10:43:24 AEDT 2019


We would like to be able to use dump_trace to dump multiple trace
buffers at a time. The entries should be displayed in timestamp order.
As each buffer is already ordered on timestamp, a k-way merge is an
efficient method to sort the buffers together by timestamp. A heap can
be used to implement a k-way merge. As CCAN is already included in
Skiboot, use the CCAN heap. The heap uses the calloc function which is
currently not defined in skiboot. Prepare for adding this heap by
defining calloc. Remove local calloc definition from libffs.c.

Signed-off-by: Jordan Niethe <jniethe5 at gmail.com>
---
 include/mem_region-malloc.h | 1 +
 libflash/libffs.c           | 8 --------
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/include/mem_region-malloc.h b/include/mem_region-malloc.h
index 58027ae7c126..41e19de585d2 100644
--- a/include/mem_region-malloc.h
+++ b/include/mem_region-malloc.h
@@ -31,6 +31,7 @@ void *__memalign(size_t boundary, size_t size, const char *location) __warn_unus
 
 #define malloc(size) __malloc(size, __location__)
 #define zalloc(size) __zalloc(size, __location__)
+#define calloc(nmemb, size) __zalloc(((nmemb) * (size)), __location__)
 #define realloc(ptr, size) __realloc(ptr, size, __location__)
 #define free(ptr) __free(ptr, __location__)
 #define memalign(boundary, size) __memalign(boundary, size, __location__)
diff --git a/libflash/libffs.c b/libflash/libffs.c
index 82caeb39f890..09448a073cc0 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -23,14 +23,6 @@
 #ifndef __SKIBOOT__
 #include <sys/types.h>
 #include <unistd.h>
-#else
-static void *calloc(size_t num, size_t size)
-{
-	void *ptr = malloc(num * size);
-	if (ptr)
-		memset(ptr, 0, num * size);
-	return ptr;
-}
 #endif
 
 #include "ffs.h"
-- 
2.20.1



More information about the Skiboot mailing list