]> git.proxmox.com Git - mirror_edk2.git/commitdiff
add error handler in return places.
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 19 Aug 2009 02:32:56 +0000 (02:32 +0000)
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 19 Aug 2009 02:32:56 +0000 (02:32 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9119 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c

index f80895bda4567afb58c29f65bf1297377383c1d6..2db5f11c6322af1ce320e9e2c502a08a9ea6485f 100644 (file)
@@ -712,12 +712,14 @@ ON_ERROR:
   if (UsbMass != NULL) {\r
     FreePool (UsbMass);\r
   }\r
-  gBS->CloseProtocol (\r
-         Controller,\r
-         &gEfiUsbIoProtocolGuid,\r
-         This->DriverBindingHandle,\r
-         Controller\r
-         );\r
+  if (UsbIo != NULL) {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiUsbIoProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+  }\r
   return Status;  \r
 }\r
 \r
@@ -830,6 +832,7 @@ USBMassDriverBindingStart (
   VOID                          *Context;\r
   UINT8                         MaxLun;\r
   EFI_STATUS                    Status;\r
+  EFI_USB_IO_PROTOCOL           *UsbIo; \r
   \r
   Transport = NULL;\r
   Context   = NULL;\r
@@ -867,18 +870,44 @@ USBMassDriverBindingStart (
       return Status;\r
     }\r
 \r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiUsbIoProtocolGuid,\r
+                    (VOID **) &UsbIo,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                    );\r
+  \r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
+      gBS->CloseProtocol (\r
+             Controller,\r
+             &gEfiDevicePathProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );\r
+      return Status;\r
+    }\r
+\r
     //\r
     // Initialize data for device that supports multiple LUNSs.\r
     // EFI_SUCCESS is returned if at least 1 LUN is initialized successfully.\r
     //\r
     Status = UsbMassInitMultiLun (This, Controller, Transport, Context, DevicePath, MaxLun);\r
     if (EFI_ERROR (Status)) {\r
-     gBS->CloseProtocol (\r
-            Controller,\r
-            &gEfiDevicePathProtocolGuid,\r
-            This->DriverBindingHandle,\r
-            Controller\r
-            );\r
+      gBS->CloseProtocol (\r
+              Controller,\r
+              &gEfiDevicePathProtocolGuid,\r
+              This->DriverBindingHandle,\r
+              Controller\r
+              );\r
+      gBS->CloseProtocol (\r
+              Controller,\r
+              &gEfiUsbIoProtocolGuid,\r
+              This->DriverBindingHandle,\r
+              Controller\r
+              );\r
       DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMultiLun (%r) with Maxlun=%d\n", Status, MaxLun));\r
     }\r
   }\r
@@ -919,9 +948,9 @@ USBMassDriverBindingStop (
   //\r
   // This is a bus driver stop function since multi-lun is supported.\r
   // There are three kinds of device handles that might be passed:\r
-  // 1st is a handle with Device Path & USB I/O & Block I/O installed (non-multi-lun)\r
+  // 1st is a handle with USB I/O & Block I/O installed (non-multi-lun)\r
   // 2nd is a handle with Device Path & USB I/O installed (multi-lun root)\r
-  // 3rd is a handle with Device Path & Block I/O installed (multi-lun).\r
+  // 3rd is a handle with Device Path & USB I/O & Block I/O installed (multi-lun).\r
   //\r
   if (NumberOfChildren == 0) {\r
     //\r
@@ -938,8 +967,8 @@ USBMassDriverBindingStop (
   \r
     if (EFI_ERROR(Status)) {\r
       //\r
-      // This is a 2nd type handle(multi-lun root), which only needs to close \r
-      // Device Path Protocol.\r
+      // This is a 2nd type handle(multi-lun root), it needs to close devicepath\r
+      // and usbio protocol.\r
       //\r
       gBS->CloseProtocol (\r
             Controller,\r
@@ -947,6 +976,12 @@ USBMassDriverBindingStop (
             This->DriverBindingHandle,\r
             Controller\r
             );\r
+      gBS->CloseProtocol (\r
+            Controller,\r
+            &gEfiUsbIoProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            Controller\r
+            );\r
       DEBUG ((EFI_D_INFO, "Success to stop multi-lun root handle\n"));\r
       return EFI_SUCCESS;\r
     }\r