From: Marek Vasut Date: Mon, 13 Aug 2018 22:33:52 +0200 Subject: [U-Boot] [PATCH v4 5/5] malloc_simple: calloc: don't call memset if malloc failed In-Reply-To: <20180813193437.9539-6-simon.k.r.goldschmidt@gmail.com> References: <20180813193437.9539-1-simon.k.r.goldschmidt@gmail.com> <20180813193437.9539-6-simon.k.r.goldschmidt@gmail.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 08/13/2018 09:34 PM, Simon Goldschmidt wrote: > 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 > Reviewed-by: Marek Vasut Separate this from the patchset, this has nothing to do with socfpga . > --- > > Changes in v4: None > Changes in v3: None > Changes in v2: None > > common/malloc_simple.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/common/malloc_simple.c b/common/malloc_simple.c > index c14f8b59c1..871b5444bd 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; > } > -- Best regards, Marek Vasut