libpayload: free: Separate NULL check out for clarity

Separate the validity check of calling free(NULL) for clarity.

BUG=b:168441735
TEST=emerge-puff libpayload

Change-Id: I0dc355553410bbe59e658945fb40c05f5f709380
Signed-off-by: Hsuan Ting Chen <roccochen@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/45465
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
Hsuan Ting Chen 2020-09-17 15:51:34 +08:00 committed by Hung-Te Lin
parent cbd0bd8155
commit 8742e2a923
1 changed files with 4 additions and 0 deletions

View File

@ -246,6 +246,10 @@ void free(void *ptr)
hdrtype_t hdr; hdrtype_t hdr;
struct memory_type *type = heap; struct memory_type *type = heap;
/* No action occurs on NULL. */
if (ptr == NULL)
return;
/* Sanity check. */ /* Sanity check. */
if (ptr < type->start || ptr >= type->end) { if (ptr < type->start || ptr >= type->end) {
type = dma; type = dma;