]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
MdeModulePkg: ScsiBusDxe: Refactor DiscoverScsiDevice()
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.c
index fbe14c772496fbbee670143d9356483186f6e522..d6c965def30b37d3eaf1b927ef29361da7ddcc58 100644 (file)
@@ -1105,7 +1105,8 @@ ScsiExecuteSCSICommand (
 \r
   @retval EFI_SUCCESS           Successfully to discover the device and attach\r
                                 ScsiIoProtocol to it.\r
-  @retval EFI_OUT_OF_RESOURCES  Fail to discover the device.\r
+  @retval EFI_NOT_FOUND         Fail to discover the device.\r
+  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1210,8 +1211,8 @@ ScsiScanCreateDevice (
     ScsiBusDev->DevicePath\r
     );\r
 \r
-  if (!DiscoverScsiDevice (ScsiIoDevice)) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
+  Status = DiscoverScsiDevice (ScsiIoDevice);\r
+  if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
 \r
@@ -1276,11 +1277,12 @@ ErrorExit:
 \r
   @param  ScsiIoDevice    The pointer of SCSI_IO_DEV\r
 \r
-  @retval  TRUE   Find SCSI Device and verify it.\r
-  @retval  FALSE  Unable to find SCSI Device.\r
+  @retval EFI_SUCCESS           Find SCSI Device and verify it.\r
+  @retval EFI_NOT_FOUND         Unable to find SCSI Device.\r
+  @retval EFI_OUT_OF_RESOURCES  Fail to allocate memory resources.\r
 \r
 **/\r
-BOOLEAN\r
+EFI_STATUS\r
 DiscoverScsiDevice (\r
   IN OUT  SCSI_IO_DEV  *ScsiIoDevice\r
   )\r
@@ -1294,7 +1296,6 @@ DiscoverScsiDevice (
   EFI_SCSI_SENSE_DATA    *SenseData;\r
   UINT8                  MaxRetry;\r
   UINT8                  Index;\r
-  BOOLEAN                ScsiDeviceFound;\r
 \r
   HostAdapterStatus = 0;\r
   TargetStatus      = 0;\r
@@ -1302,7 +1303,7 @@ DiscoverScsiDevice (
 \r
   InquiryData = AllocateAlignedBuffer (ScsiIoDevice, sizeof (EFI_SCSI_INQUIRY_DATA));\r
   if (InquiryData == NULL) {\r
-    ScsiDeviceFound = FALSE;\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -1311,7 +1312,7 @@ DiscoverScsiDevice (
                 sizeof (EFI_SCSI_SENSE_DATA)\r
                 );\r
   if (SenseData == NULL) {\r
-    ScsiDeviceFound = FALSE;\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -1342,7 +1343,7 @@ DiscoverScsiDevice (
           (SenseData->Error_Code == 0x70) &&\r
           (SenseData->Sense_Key == EFI_SCSI_SK_ILLEGAL_REQUEST))\r
       {\r
-        ScsiDeviceFound = FALSE;\r
+        Status = EFI_NOT_FOUND;\r
         goto Done;\r
       }\r
 \r
@@ -1353,13 +1354,13 @@ DiscoverScsiDevice (
         (Status == EFI_INVALID_PARAMETER) ||\r
         (Status == EFI_UNSUPPORTED))\r
     {\r
-      ScsiDeviceFound = FALSE;\r
+      Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
   }\r
 \r
   if (Index == MaxRetry) {\r
-    ScsiDeviceFound = FALSE;\r
+    Status = EFI_NOT_FOUND;\r
     goto Done;\r
   }\r
 \r
@@ -1367,14 +1368,14 @@ DiscoverScsiDevice (
   // Retrieved inquiry data successfully\r
   //\r
   if (InquiryData->Peripheral_Qualifier != 0) {\r
-    ScsiDeviceFound = FALSE;\r
+    Status = EFI_NOT_FOUND;\r
     goto Done;\r
   }\r
 \r
   if ((InquiryData->Peripheral_Type >= EFI_SCSI_TYPE_RESERVED_LOW) &&\r
       (InquiryData->Peripheral_Type <= EFI_SCSI_TYPE_RESERVED_HIGH))\r
   {\r
-    ScsiDeviceFound = FALSE;\r
+    Status = EFI_NOT_FOUND;\r
     goto Done;\r
   }\r
 \r
@@ -1392,13 +1393,13 @@ DiscoverScsiDevice (
     ScsiIoDevice->ScsiVersion = (UINT8)(InquiryData->Version & 0x07);\r
   }\r
 \r
-  ScsiDeviceFound = TRUE;\r
+  Status = EFI_SUCCESS;\r
 \r
 Done:\r
   FreeAlignedBuffer (SenseData, sizeof (EFI_SCSI_SENSE_DATA));\r
   FreeAlignedBuffer (InquiryData, sizeof (EFI_SCSI_INQUIRY_DATA));\r
 \r
-  return ScsiDeviceFound;\r
+  return Status;\r
 }\r
 \r
 /**\r