]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: ScsiBusDxe: Refactor DiscoverScsiDevice()
authorYuan Yu <yuanyu@google.com>
Tue, 31 Jan 2023 06:03:47 +0000 (14:03 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 2 Feb 2023 01:58:08 +0000 (01:58 +0000)
Currently DiscoverScsiDevice() returns a boolean which cannot
distinguish a "not found" situation from a real problem like
memory allocation failures.

This patch changes the return value to an EFI_STATUS so that when
memory allocation fails, it will return EFI_OUT_OF_RESOURCES.

Without this change, any FALSE returned by DiscoverScsiDevice()
will result in EFI_OUT_OF_RESOURCES being returned by
ScsiScanCreateDevice(), which will cause a while loop in
SCSIBusDriverBindingStart() to abort before other possible Puns in
the SCSI channel are scanned, which means good devices may not have
a chance to be discovered.  If this good device is the boot device,
boot will fail.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sivaparvathi chellaiah <sivaparvathic@ami.com>
Signed-off-by: Yuan Yu <yuanyu@google.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h

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
index 68c5c02a916138b3afe062db408f073df07fe57b..35a8a46ca7a2b98287583890a2adb843ac412212 100644 (file)
@@ -455,7 +455,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
@@ -473,11 +474,12 @@ ScsiScanCreateDevice (
 \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