ArmPkg/BdsLib: Fix allocating kernel buffer in TFTP

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brendan Jackman <Brendan.JackMan@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15527 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Brendan Jackman 2014-05-14 16:39:43 +00:00 committed by oliviermartin
parent 48ef4e4276
commit 1aaa6f61a5
1 changed files with 11 additions and 8 deletions

View File

@ -756,7 +756,6 @@ BdsTftpLoadImage (
EFI_STATUS Status; EFI_STATUS Status;
EFI_PXE_BASE_CODE_PROTOCOL *Pxe; EFI_PXE_BASE_CODE_PROTOCOL *Pxe;
UINT64 TftpBufferSize; UINT64 TftpBufferSize;
VOID* TftpBuffer;
EFI_IP_ADDRESS ServerIp; EFI_IP_ADDRESS ServerIp;
IPv4_DEVICE_PATH* IPv4DevicePathNode; IPv4_DEVICE_PATH* IPv4DevicePathNode;
FILEPATH_DEVICE_PATH* FilePathDevicePath; FILEPATH_DEVICE_PATH* FilePathDevicePath;
@ -838,16 +837,21 @@ BdsTftpLoadImage (
} }
// Allocate a buffer to hold the whole file. // Allocate a buffer to hold the whole file.
TftpBuffer = AllocatePool (TftpBufferSize); Status = gBS->AllocatePages (
if (TftpBuffer == NULL) { Type,
Status = EFI_OUT_OF_RESOURCES; EfiBootServicesCode,
EFI_SIZE_TO_PAGES (TftpBufferSize),
Image
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "Failed to allocate space for kernel image: %r\n", Status));
goto EXIT; goto EXIT;
} }
Status = Pxe->Mtftp ( Status = Pxe->Mtftp (
Pxe, Pxe,
EFI_PXE_BASE_CODE_TFTP_READ_FILE, EFI_PXE_BASE_CODE_TFTP_READ_FILE,
TftpBuffer, (VOID *)(UINTN)*Image,
FALSE, FALSE,
&TftpBufferSize, &TftpBufferSize,
NULL, NULL,
@ -857,9 +861,8 @@ BdsTftpLoadImage (
FALSE FALSE
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePool (TftpBuffer); gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));
} else if (ImageSize != NULL) { } else {
*Image = (UINTN)TftpBuffer;
*ImageSize = (UINTN)TftpBufferSize; *ImageSize = (UINTN)TftpBufferSize;
} }