summaryrefslogtreecommitdiff
path: root/src/lib/malloc.c
diff options
context:
space:
mode:
authorTim Wawrzynczak <twawrzynczak@chromium.org>2021-03-30 11:49:14 -0600
committerPatrick Georgi <pgeorgi@google.com>2021-04-06 06:50:38 +0000
commitc556dffe985067cc40b817e963dae5cd1c34cc74 (patch)
tree3215c4fee56bdf4870864e72471d77f508fae32a /src/lib/malloc.c
parent8aedb34501450920a663342429e409562431e1c2 (diff)
lib: Add obvious definition for `calloc`
The calloc() function is useful in addition to malloc and friends, so add the obvious definition. Change-Id: I57a568e323344a97b35014b7b8bec16adc2fd720 Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/51949 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib/malloc.c')
-rw-r--r--src/lib/malloc.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lib/malloc.c b/src/lib/malloc.c
index cd86f99f0b..7d787d631e 100644
--- a/src/lib/malloc.c
+++ b/src/lib/malloc.c
@@ -1,5 +1,6 @@
-#include <stdlib.h>
#include <console/console.h>
+#include <stdlib.h>
+#include <string.h>
#if CONFIG(DEBUG_MALLOC)
#define MALLOCDBG(x...) printk(BIOS_SPEW, x)
@@ -54,6 +55,15 @@ void *malloc(size_t size)
return memalign(sizeof(u64), size);
}
+void *calloc(size_t nitems, size_t size)
+{
+ void *p = malloc(nitems * size);
+ if (p)
+ memset(p, 0, nitems * size);
+
+ return p;
+}
+
void free(void *ptr)
{
if (ptr == NULL)