]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Fat.c
Move lock to FAT driver binding start to prevent interrupt during hot plug event.
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Fat.c
index 67ee66c026c19a1341c09b90c229da8beb0c774d..38b70882c5c5ca796af0216c9437e1ca9512030e 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -269,10 +269,21 @@ Returns:
   EFI_STATUS            Status;\r
   EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
   EFI_DISK_IO_PROTOCOL  *DiskIo;\r
+  BOOLEAN               LockedByMe;\r
+\r
+  LockedByMe = FALSE;\r
+  //\r
+  // Acquire the lock.\r
+  // If caller has already acquired the lock, cannot lock it again.\r
+  //\r
+  Status = FatAcquireLockOrFail ();\r
+  if (!EFI_ERROR (Status)) {\r
+    LockedByMe = TRUE;\r
+  }\r
 \r
   Status = InitializeUnicodeCollationSupport (This->DriverBindingHandle);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Exit;\r
   }\r
   //\r
   // Open our required BlockIo and DiskIo\r
@@ -286,7 +297,7 @@ Returns:
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Exit;\r
   }\r
 \r
   Status = gBS->OpenProtocol (\r
@@ -298,7 +309,7 @@ Returns:
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Exit;\r
   }\r
   //\r
   // Allocate Volume structure. In FatAllocateVolume(), Resources\r
@@ -330,6 +341,13 @@ Returns:
     }\r
   }\r
 \r
+Exit:\r
+  //\r
+  // Unlock if locked by myself.\r
+  //\r
+  if (LockedByMe) {\r
+    FatReleaseLock ();\r
+  }\r
   return Status;\r
 }\r
 \r