From d83ae9c923b2b271ffd2a86279dad91c7713146d Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 15 Oct 2018 10:00:17 -0700 Subject: tlsf_malloc: dummy_malloc: Share code for calloc() Calloc() implementation for TLSF does not correctly check for malloc() failure which can result in a NULL pointer exception when trying to calloc() extra large buffers. Since both TLSF and dummy malloc implementations of calloc() are exactly the same, pick implementation for the latter (which does aforementioned check) and share it between the two. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/calloc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 common/calloc.c (limited to 'common/calloc.c') diff --git a/common/calloc.c b/common/calloc.c new file mode 100644 index 0000000000..2b933ec272 --- /dev/null +++ b/common/calloc.c @@ -0,0 +1,19 @@ +#include +#include + +/* + * calloc calls malloc, then zeroes out the allocated chunk. + */ +void *calloc(size_t n, size_t elem_size) +{ + size_t size = elem_size * n; + void *r = malloc(size); + + if (!r) + return r; + + memset(r, 0x0, size); + + return r; +} +EXPORT_SYMBOL(calloc); -- cgit v1.2.3