Revision: 16586
          http://sourceforge.net/p/edk2/code/16586
Author:   oliviermartin
Date:     2015-01-06 15:51:02 +0000 (Tue, 06 Jan 2015)
Log Message:
-----------
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 <[email protected]>
Reviewed-by: Olivier Martin <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ArmPkg/Library/BdsLib/BdsFilePath.c

Modified: trunk/edk2/ArmPkg/Library/BdsLib/BdsFilePath.c
===================================================================
--- trunk/edk2/ArmPkg/Library/BdsLib/BdsFilePath.c      2015-01-06 15:49:51 UTC 
(rev 16585)
+++ trunk/edk2/ArmPkg/Library/BdsLib/BdsFilePath.c      2015-01-06 15:51:02 UTC 
(rev 16586)
@@ -467,27 +467,34 @@
 
 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 @@
   // 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 @@
   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 @@
     Status = File->Read (File, &Size, (VOID*)(UINTN)(*Image));
   }
 
+CLOSE_FILE:
+  File->Close (File);
+
+CLOSE_PROTOCOL:
+  gBS->CloseProtocol (
+         Handle,
+         &gEfiSimpleFileSystemProtocolGuid,
+         gImageHandle,
+         Handle);
+
   return Status;
 }
 


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to