]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiDriver.c
NetworkPkg: Fix Assert issue in iSCSI driver.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiDriver.c
index a7031dfc4ed8d47c77c6b0672b269840ad257dca..c3ab2c92881d6041aceac0329732f3cfee2a6c0c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The entry point of IScsi driver.\r
 \r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -105,7 +105,8 @@ IScsiCheckAip (
   //\r
   // Check any AIP instances exist in system.\r
   //\r
-  AipHandleCount = 0;\r
+  AipHandleCount  = 0;\r
+  AipHandleBuffer = NULL;\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
                   &gEfiAdapterInformationProtocolGuid,\r
@@ -117,6 +118,8 @@ IScsiCheckAip (
     return EFI_NOT_FOUND;\r
   }\r
 \r
+  ASSERT (AipHandleBuffer != NULL);\r
+\r
   InfoBlock = NULL;\r
 \r
   for (AipIndex = 0; AipIndex < AipHandleCount; AipIndex++) {\r
@@ -320,7 +323,10 @@ IScsiSupported (
   @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
   @retval EFI_NOT_FOUND         There is no sufficient information to establish\r
                                 the iScsi session.\r
-  @retval EFI_DEVICE_ERROR      Failed to get TCP connection device path.                              \r
+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory.\r
+  @retval EFI_DEVICE_ERROR      Failed to get TCP connection device path.\r
+  @retval EFI_ACCESS_DENIED     The protocol could not be removed from the Handle\r
+                                because its interfaces are being used.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -666,7 +672,7 @@ IScsiStart (
     Session->ConfigData = AttemptConfigData;\r
     Session->AuthType   = AttemptConfigData->AuthenticationType;\r
 \r
-    AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);\r
+    AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, sizeof (MacString) / sizeof (MacString[0]));\r
     UnicodeSPrint (\r
       mPrivate->PortString,\r
       (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
@@ -860,7 +866,22 @@ IScsiStart (
           IScsiSessionAbort (ExistPrivate->Session);\r
         }\r
 \r
-        IScsiCleanDriverData (ExistPrivate);\r
+        if (ExistPrivate->DevicePath != NULL) {\r
+          Status = gBS->UninstallProtocolInterface (\r
+                          ExistPrivate->ExtScsiPassThruHandle,\r
+                          &gEfiDevicePathProtocolGuid,\r
+                          ExistPrivate->DevicePath\r
+                          );\r
+          if (EFI_ERROR (Status)) {\r
+            goto ON_ERROR;\r
+          }\r
+\r
+          FreePool (ExistPrivate->DevicePath);\r
+        }\r
+\r
+        gBS->CloseEvent (ExistPrivate->ExitBootServiceEvent);\r
+        FreePool (ExistPrivate);\r
+\r
       }\r
     } else {\r
       //\r
@@ -960,6 +981,9 @@ ON_ERROR:
   \r
   @retval EFI_SUCCESS           The device was stopped.\r
   @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+  @retval EFI_INVALID_PARAMETER Child handle is NULL.\r
+  @retval EFI_ACCESS_DENIED     The protocol could not be removed from the Handle\r
+                                because its interfaces are being used.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1102,7 +1126,11 @@ IScsiStop (
     IScsiSessionAbort (Private->Session);\r
   }\r
 \r
-  IScsiCleanDriverData (Private);\r
+  Status = IScsiCleanDriverData (Private);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r