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_PXE_BASE_CODE_PROTOCOL *Pxe;
UINT64 TftpBufferSize;
VOID* TftpBuffer;
EFI_IP_ADDRESS ServerIp;
IPv4_DEVICE_PATH* IPv4DevicePathNode;
FILEPATH_DEVICE_PATH* FilePathDevicePath;
@ -838,16 +837,21 @@ BdsTftpLoadImage (
}
// Allocate a buffer to hold the whole file.
TftpBuffer = AllocatePool (TftpBufferSize);
if (TftpBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
Status = gBS->AllocatePages (
Type,
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;
}
Status = Pxe->Mtftp (
Pxe,
EFI_PXE_BASE_CODE_TFTP_READ_FILE,
TftpBuffer,
(VOID *)(UINTN)*Image,
FALSE,
&TftpBufferSize,
NULL,
@ -857,9 +861,8 @@ BdsTftpLoadImage (
FALSE
);
if (EFI_ERROR (Status)) {
FreePool (TftpBuffer);
} else if (ImageSize != NULL) {
*Image = (UINTN)TftpBuffer;
gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));
} else {
*ImageSize = (UINTN)TftpBufferSize;
}