Ravi Kumar Bokka has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/63026 )
Change subject: soc/qualcomm/common: verify size of memchipinfo structure ......................................................................
soc/qualcomm/common: verify size of memchipinfo structure
BUG=b:182963902,b:177917361 TEST=Validated on qualcomm sc7280 development board
Signed-off-by: Ravi Kumar Bokka rbokka@codeaurora.org Change-Id: I0d59669adaf287d0eb7b58ccb0fe3f98e3d23281 --- M src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h M src/soc/qualcomm/common/qclib.c 2 files changed, 19 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/26/63026/1
diff --git a/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h b/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h index 8dc6db3..43d1c60 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h +++ b/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h @@ -25,4 +25,8 @@ } channel[0]; };
+static inline size_t mem_chip_info_size(struct mem_chip_info *info) { + return sizeof(*info) + sizeof(info->channel[0]) * info->num_channels; +}; + #endif /* _COMMONLIB_BSD_MEM_CHIP_INFO_H_ */ diff --git a/src/soc/qualcomm/common/qclib.c b/src/soc/qualcomm/common/qclib.c index 9a485db..afa67e3 100644 --- a/src/soc/qualcomm/common/qclib.c +++ b/src/soc/qualcomm/common/qclib.c @@ -25,12 +25,24 @@
static void write_mem_chip_information(struct qclib_cb_if_table_entry *te) { - /* Save mem_chip_info in local variables ahead of hook running */ - mem_chip_addr = (void *)te->blob_address; + struct mem_chip_info memchip; + memchip.num_channels = 2; + + if (te->size == mem_chip_info_size(&memchip)) { + /* Save mem_chip_info in local variables ahead of hook running */ + mem_chip_addr = (void *)te->blob_address; + } + + if (!mem_chip_addr) { + printk(BIOS_ERR, "Did not receive valid mem_chip_info from QcLib!"); + return; + } }
static void add_mem_chip_info(int unused) { + struct mem_chip_info memchip; + memchip.num_channels = 2; void *mem_region_base = NULL;
/* Add cbmem table */ @@ -40,7 +52,7 @@ ASSERT(mem_region_base != NULL);
/* Migrate the data into CBMEM */ - memcpy(mem_region_base, mem_chip_addr, sizeof(struct mem_chip_info)); + memcpy(mem_region_base, mem_chip_addr, mem_chip_info_size(&memchip)); }
ROMSTAGE_CBMEM_INIT_HOOK(add_mem_chip_info);