summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonald Cron <Ronald.Cron@arm.com>2015-01-06 15:51:02 +0000
committeroliviermartin <oliviermartin@Edk2>2015-01-06 15:51:02 +0000
commitad7e31b505b91c9e7baf266dd8cf2ff95befbb8a (patch)
treeeb2b1b0ac7eb8720b925592b2420283c83df9eb6
parentf98f9d98089be8b5b33669cf6e09f14b819dafc4 (diff)
downloadedk2-platforms-ad7e31b505b91c9e7baf266dd8cf2ff95befbb8a.tar.xz
ArmPkg/BdsLib: Close file after reading an Image
When loading an image from a file, close the file after reading from it. Use OpenProtocol instead of HandleProtocol to retrieve the simple file system protocol interface. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ronald Cron <Ronald.Cron@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16586 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--ArmPkg/Library/BdsLib/BdsFilePath.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/ArmPkg/Library/BdsLib/BdsFilePath.c b/ArmPkg/Library/BdsLib/BdsFilePath.c
index 5fc8d53092..924c61ed34 100644
--- a/ArmPkg/Library/BdsLib/BdsFilePath.c
+++ b/ArmPkg/Library/BdsLib/BdsFilePath.c
@@ -467,27 +467,34 @@ BdsFileSystemSupport (
EFI_STATUS
BdsFileSystemLoadImage (
- IN EFI_DEVICE_PATH *DevicePath,
- IN EFI_HANDLE Handle,
- IN EFI_DEVICE_PATH *RemainingDevicePath,
+ IN EFI_DEVICE_PATH *DevicePath,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH *RemainingDevicePath,
IN EFI_ALLOCATE_TYPE Type,
- IN OUT EFI_PHYSICAL_ADDRESS* Image,
+ IN OUT EFI_PHYSICAL_ADDRESS *Image,
OUT UINTN *ImageSize
)
{
- FILEPATH_DEVICE_PATH* FilePathDevicePath;
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;
- EFI_FILE_PROTOCOL *Fs;
- EFI_STATUS Status;
- EFI_FILE_INFO *FileInfo;
- EFI_FILE_PROTOCOL *File;
- UINTN Size;
+ EFI_STATUS Status;
+ FILEPATH_DEVICE_PATH *FilePathDevicePath;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;
+ EFI_FILE_PROTOCOL *Fs;
+ EFI_FILE_INFO *FileInfo;
+ EFI_FILE_PROTOCOL *File;
+ UINTN Size;
ASSERT (IS_DEVICE_PATH_NODE (RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP));
FilePathDevicePath = (FILEPATH_DEVICE_PATH*)RemainingDevicePath;
- Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ (VOID**)&FsProtocol,
+ gImageHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -495,13 +502,12 @@ BdsFileSystemLoadImage (
// Try to Open the volume and get root directory
Status = FsProtocol->OpenVolume (FsProtocol, &Fs);
if (EFI_ERROR (Status)) {
- return Status;
+ goto CLOSE_PROTOCOL;
}
- File = NULL;
Status = Fs->Open (Fs, &File, FilePathDevicePath->PathName, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
- return Status;
+ goto CLOSE_PROTOCOL;
}
Size = 0;
@@ -509,7 +515,7 @@ BdsFileSystemLoadImage (
FileInfo = AllocatePool (Size);
Status = File->GetInfo (File, &gEfiFileInfoGuid, &Size, FileInfo);
if (EFI_ERROR (Status)) {
- return Status;
+ goto CLOSE_FILE;
}
// Get the file size
@@ -528,6 +534,16 @@ BdsFileSystemLoadImage (
Status = File->Read (File, &Size, (VOID*)(UINTN)(*Image));
}
+CLOSE_FILE:
+ File->Close (File);
+
+CLOSE_PROTOCOL:
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ gImageHandle,
+ Handle);
+
return Status;
}