From: Ranbir Singh <ranbir.sin...@dell.com>

The function SubmitResources has a switch-case code in which the
case ACPI_ADDRESS_SPACE_TYPE_MEM: which falls through to
case ACPI_ADDRESS_SPACE_TYPE_IO: to include additional common check.

While this may be intentional, it may not be evident to any general code
reader/developer or static analyis tool why there is no break in between.

SubmitResources function is supposed to handle only Mem or IO resources.
So, update the ResType parameter check reflecting that and re-model the
switch-case code in contention using just one if condition to further
handle other parameter checks specific to ACPI_ADDRESS_SPACE_TYPE_MEM.
This leads to mostly indentation level code changes. Few ASSERT's later
present are henceforth not required.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4212

Cc: Ray Ni <ray...@intel.com>
Signed-off-by: Ranbir Singh <rsi...@ventanamicro.com>
---
 MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 60 +++++++++-----------
 1 file changed, 26 insertions(+), 34 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c 
b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c
index c2c143068cd2..ed0aa455bfd4 100644
--- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c
+++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c
@@ -1453,7 +1453,7 @@ SetBusNumbers (
   Submits the I/O and memory resource requirements for the specified PCI Root 
Bridge.
 
   @param This              The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ 
PROTOCOL instance.
-  @param RootBridgeHandle  The PCI Root Bridge whose I/O and memory resource 
requirements.
+  @param RootBridgeHandle  The PCI Root Bridge whose I/O and memory resource 
requirements
                            are being submitted.
   @param Configuration     The pointer to the PCI I/O and PCI memory resource 
descriptor.
 
@@ -1496,7 +1496,7 @@ SubmitResources (
       // descriptors are ignored and the function returns 
EFI_INVALID_PARAMETER.
       //
       for (Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Configuration; 
Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
-        if (Descriptor->ResType > ACPI_ADDRESS_SPACE_TYPE_BUS) {
+        if ((Descriptor->ResType != ACPI_ADDRESS_SPACE_TYPE_MEM) && 
(Descriptor->ResType != ACPI_ADDRESS_SPACE_TYPE_IO)) {
           return EFI_INVALID_PARAMETER;
         }
 
@@ -1509,40 +1509,34 @@ SubmitResources (
           (Descriptor->SpecificFlag & 
EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) != 0 ? L" 
(Prefetchable)" : L""
           ));
         DEBUG ((DEBUG_INFO, "      Length/Alignment = 0x%lx / 0x%lx\n", 
Descriptor->AddrLen, Descriptor->AddrRangeMax));
-        switch (Descriptor->ResType) {
-          case ACPI_ADDRESS_SPACE_TYPE_MEM:
-            if ((Descriptor->AddrSpaceGranularity != 32) && 
(Descriptor->AddrSpaceGranularity != 64)) {
-              return EFI_INVALID_PARAMETER;
-            }
 
-            if ((Descriptor->AddrSpaceGranularity == 32) && 
(Descriptor->AddrLen >= SIZE_4GB)) {
-              return EFI_INVALID_PARAMETER;
-            }
+        if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {
+          if ((Descriptor->AddrSpaceGranularity != 32) && 
(Descriptor->AddrSpaceGranularity != 64)) {
+            return EFI_INVALID_PARAMETER;
+          }
 
-            //
-            // If the PCI root bridge does not support separate windows for 
nonprefetchable and
-            // prefetchable memory, then the PCI bus driver needs to include 
requests for
-            // prefetchable memory in the nonprefetchable memory pool.
-            //
-            if (((RootBridge->AllocationAttributes & 
EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM) != 0) &&
-                ((Descriptor->SpecificFlag & 
EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) != 0)
-                )
-            {
-              return EFI_INVALID_PARAMETER;
-            }
+          if ((Descriptor->AddrSpaceGranularity == 32) && (Descriptor->AddrLen 
>= SIZE_4GB)) {
+            return EFI_INVALID_PARAMETER;
+          }
 
-          case ACPI_ADDRESS_SPACE_TYPE_IO:
-            //
-            // Check aligment, it should be of the form 2^n-1
-            //
-            if (GetPowerOfTwo64 (Descriptor->AddrRangeMax + 1) != 
(Descriptor->AddrRangeMax + 1)) {
-              return EFI_INVALID_PARAMETER;
-            }
+          //
+          // If the PCI root bridge does not support separate windows for 
nonprefetchable and
+          // prefetchable memory, then the PCI bus driver needs to include 
requests for
+          // prefetchable memory in the nonprefetchable memory pool.
+          //
+          if (((RootBridge->AllocationAttributes & 
EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM) != 0) &&
+              ((Descriptor->SpecificFlag & 
EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) != 0)
+              )
+          {
+            return EFI_INVALID_PARAMETER;
+          }
+        }
 
-            break;
-          default:
-            ASSERT (FALSE);
-            break;
+        //
+        // Check aligment, it should be of the form 2^n-1
+        //
+        if (GetPowerOfTwo64 (Descriptor->AddrRangeMax + 1) != 
(Descriptor->AddrRangeMax + 1)) {
+          return EFI_INVALID_PARAMETER;
         }
       }
 
@@ -1559,7 +1553,6 @@ SubmitResources (
               Type = TypeMem32;
             }
           } else {
-            ASSERT (Descriptor->AddrSpaceGranularity == 64);
             if ((Descriptor->SpecificFlag & 
EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE) != 0) {
               Type = TypePMem64;
             } else {
@@ -1567,7 +1560,6 @@ SubmitResources (
             }
           }
         } else {
-          ASSERT (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_IO);
           Type = TypeIo;
         }
 
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110994): https://edk2.groups.io/g/devel/message/110994
Mute This Topic: https://groups.io/mt/102490514/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to