]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: Fix GT Block length assignment
authorSami Mujawar <sami.mujawar@arm.com>
Tue, 9 Jul 2019 12:54:04 +0000 (13:54 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sun, 29 Mar 2020 16:53:35 +0000 (16:53 +0000)
The VS2017 compiler reports 'warning C4267: '=': conversion from
'size_t' to 'UINT16', possible loss of data'.

The sizeof() operator is used to calculate the size of the
GT Block structure. The length field in the GT Block structure
is 16-bit wide. Since the return type of sizeof() operator
is size_t the VS2017 compiler reports the above warning.

To fix the warning, an explicit type cast is added. An additional
check is also performed to ensure that the calculated GT Block
length does not exceed MAX_UINT16.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c

index 7e86c30649bd36ecebac75c7e3a86a0c25cd590b..0e996698887aefca8a7240fc27fe3cb9324fd3e2 100644 (file)
@@ -350,6 +350,7 @@ AddGTBlockList (
   EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCTURE  * GtBlockFrame;\r
   CM_ARM_GTBLOCK_TIMER_FRAME_INFO             * GTBlockTimerFrameList;\r
   UINT32                                        GTBlockTimerFrameCount;\r
+  UINTN                                         Length;\r
 \r
   ASSERT (Gtdt != NULL);\r
   ASSERT (GTBlockInfo != NULL);\r
@@ -376,11 +377,27 @@ AddGTBlockList (
       return Status;\r
     }\r
 \r
-    GTBlock->Type = EFI_ACPI_6_3_GTDT_GT_BLOCK;\r
-    GTBlock->Length = sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_STRUCTURE) +\r
-                        (sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCTURE) *\r
-                          GTBlockInfo->GTBlockTimerFrameCount);\r
+    Length = sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_STRUCTURE) +\r
+               (sizeof (EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCTURE) *\r
+                GTBlockInfo->GTBlockTimerFrameCount);\r
 \r
+    // Check that the length of the GT block does not\r
+    // exceed MAX_UINT16\r
+    if (Length > MAX_UINT16) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      DEBUG ((\r
+        DEBUG_ERROR,\r
+        "ERROR: GTDT: Too many GT Frames. Count = %d. " \\r
+        "Maximum supported GT Block size exceeded. " \\r
+        "Status = %r\n",\r
+        GTBlockInfo->GTBlockTimerFrameCount,\r
+        Status\r
+        ));\r
+      return Status;\r
+    }\r
+\r
+    GTBlock->Type = EFI_ACPI_6_3_GTDT_GT_BLOCK;\r
+    GTBlock->Length = (UINT16)Length;\r
     GTBlock->Reserved = EFI_ACPI_RESERVED_BYTE;\r
     GTBlock->CntCtlBase = GTBlockInfo->GTBlockPhysicalAddress;\r
     GTBlock->GTBlockTimerCount = GTBlockInfo->GTBlockTimerFrameCount;\r