aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Goldschmidt2018-08-16 09:50:32 +0200
committerTom Rini2018-08-24 13:20:19 -0400
commitf3da76ea8b4c559ac0dc9206dc1676dde2224cd8 (patch)
treefe749c4817f565b0f109ac032101d781aad2018b
parenta5e34fc0b628627cbda444a19a896895cfb4c552 (diff)
malloc_simple: calloc: don't call memset if malloc failed
malloc_simple() can return 0 if out of memory. Don't call memset from calloc() in this case but rely on the caller checking the return value. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Marek Vasut <marex@denx.de>
-rw-r--r--common/malloc_simple.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index c14f8b59c17..871b5444bd7 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -57,7 +57,8 @@ void *calloc(size_t nmemb, size_t elem_size)
void *ptr;
ptr = malloc(size);
- memset(ptr, '\0', size);
+ if (ptr)
+ memset(ptr, '\0', size);
return ptr;
}