StandaloneMmPlg/StandaloneMmIpPei: Fix use without initialization
Update logic to prevent case where PlatformHobList may be used without being initialized. Check for expected return statuses and values from first call to CreateMmPlatformHob(). Remove use of CpuDeadLoop() and instead make consistent use of DEBUG_ERROR log messages and ASSERT()s to detect unexpected failures determining the size and allocating the platform HOB List for the Standalone MM environment. Fix potential memory leak when the expected allocation size does not match the actual allocation size. Fixes a build error detected with CLANG 20.1.0. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
committed by
mergify[bot]
parent
18164e8c69
commit
62549edb9f
@@ -411,24 +411,35 @@ CreatMmHobList (
|
||||
PlatformHobSize = 0;
|
||||
Status = CreateMmPlatformHob (NULL, &PlatformHobSize);
|
||||
if (Status == RETURN_BUFFER_TOO_SMALL) {
|
||||
ASSERT (PlatformHobSize != 0);
|
||||
if (PlatformHobSize == 0) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: PlatformHobSize is zero, cannot create MM HOBs\n", __func__));
|
||||
ASSERT (PlatformHobSize != 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Create platform HOBs for MM foundation to get MMIO HOB data.
|
||||
//
|
||||
PlatformHobList = AllocatePages (EFI_SIZE_TO_PAGES (PlatformHobSize));
|
||||
ASSERT (PlatformHobList != NULL);
|
||||
if (PlatformHobList == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: Out of resource to create platform MM HOBs\n", __func__));
|
||||
CpuDeadLoop ();
|
||||
ASSERT (PlatformHobList != NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BufferSize = PlatformHobSize;
|
||||
Status = CreateMmPlatformHob (PlatformHobList, &PlatformHobSize);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
ASSERT (BufferSize == PlatformHobSize);
|
||||
if (BufferSize != PlatformHobSize) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: CreateMmPlatformHob returned unexpected size (%d != %d)\n", __func__, BufferSize, PlatformHobSize));
|
||||
FreePages (PlatformHobList, EFI_SIZE_TO_PAGES (PlatformHobSize));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: CreateMmPlatformHob failed (%r)\n", __func__, Status));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Build memory allocation HOB in PEI HOB list for MM profile data.
|
||||
|
||||
Reference in New Issue
Block a user