]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: Fix Proc node length assignment
authorSami Mujawar <sami.mujawar@arm.com>
Tue, 9 Jul 2019 12:35:02 +0000 (13:35 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sun, 29 Mar 2020 16:53:35 +0000 (16:53 +0000)
The length field for the Processor Hierarchy node structure is
8-bit wide while the number of private resource field is 32-bit
wide. Therefore, the GetProcHierarchyNodeSize() returns the size
as a 32-bit value.

The VS2017 compiler reports 'warning C4244: '=': conversion from
'UINT32' to 'UINT8', possible loss of data' while assigning the
length field of the Processor Hierarchy node structure.

To fix this, a type cast is added. In addition, there is a check
to ensure that the Processor Hierarchy node size does not exceed
MAX_UINT8.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>
DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c

index 9e42eee9b75bb330833b0f56c98947563d9eb821..40699ce113caa8530c89ac20562cf5abda26b88e 100644 (file)
@@ -504,6 +504,7 @@ AddProcHierarchyNodes (
 \r
   PPTT_NODE_INDEXER                     * ProcNodeIterator;\r
   UINT32                                  NodeCount;\r
+  UINT32                                  Length;\r
 \r
   ASSERT (\r
     (Generator != NULL) &&\r
@@ -539,8 +540,8 @@ AddProcHierarchyNodes (
     // imposed on the Processor Hierarchy node by the specification.\r
     // Note: The length field is 8 bit wide while the number of private\r
     // resource field is 32 bit wide.\r
-    if ((sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR) +\r
-        (ProcInfoNode->NoOfPrivateResources * sizeof (UINT32))) > MAX_UINT8) {\r
+    Length = GetProcHierarchyNodeSize (ProcInfoNode);\r
+    if (Length > MAX_UINT8) {\r
       Status = EFI_INVALID_PARAMETER;\r
       DEBUG ((\r
         DEBUG_ERROR,\r
@@ -556,7 +557,7 @@ AddProcHierarchyNodes (
 \r
     // Populate the node header\r
     ProcStruct->Type = EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR;\r
-    ProcStruct->Length = GetProcHierarchyNodeSize (ProcInfoNode);\r
+    ProcStruct->Length = (UINT8)Length;\r
     ProcStruct->Reserved[0] = EFI_ACPI_RESERVED_BYTE;\r
     ProcStruct->Reserved[1] = EFI_ACPI_RESERVED_BYTE;\r
 \r