src/soc/intel: Avoid NULL pointer dereference

Coverity detects pointer mem_info as NULL_RETURNS. Add sanity check
for mem_info to prevent NULL pointer dereference.

BUG=CID 1401394
TEST=Built and boot up to kernel.

Change-Id: I9d78ab38b8b2dd3734e0143acfd88d9093f16ce6
Signed-off-by: John Zhao <john.zhao@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33152
Reviewed-by: Martin Roth <martinroth@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
John Zhao 2019-05-31 10:44:46 -07:00 committed by Martin Roth
parent 9995418166
commit 317cbd6f02
1 changed files with 6 additions and 0 deletions

View File

@ -122,6 +122,12 @@ void raminit(struct pei_data *pei_data)
printk(BIOS_DEBUG, "create cbmem for dimm information\n");
mem_info = cbmem_add(CBMEM_ID_MEMINFO, sizeof(struct memory_info));
if (!mem_info) {
printk(BIOS_ERR, "Error! Failed to add mem_info to cbmem\n");
return;
}
memset(mem_info, 0, sizeof(*mem_info));
/* Translate pei_memory_info struct data into memory_info struct */
mem_info->dimm_cnt = pei_data->meminfo.dimm_cnt;