]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: Fix serial port subtype warning
authorSami Mujawar <sami.mujawar@arm.com>
Tue, 9 Jul 2019 10:56:14 +0000 (11:56 +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 C4244: '=': conversion
from 'UINT16' to 'UINT8', possible loss of data' for the
SPCR InterfaceType field assignment.

The SPCR InterfaceType field uses the same encoding as that
of the DBG2 table Port Subtype field. However SPCR.InterfaceType
is 8-bit while the Port Subtype field in DBG2 table is 16-bit.

Since the Configuration Manager represents the Serial port
information using the struct CM_ARM_SERIAL_PORT_INFO, the
PortSubtype member in this struct is 16-bit.

To fix the warning an explicit type case is added. A validation
is also added to ensure that the Serial Port Subtype value
provided by the Configuration Manager is within the 8-bit
range (less than 256).

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/AcpiSpcrLibArm/SpcrGenerator.c

index 1404279f828d5c06bb7605cb2fe6d864ef7a080e..4b2580da7df9b4472ae9bcc3df2138a9e13004d0 100644 (file)
@@ -217,8 +217,21 @@ BuildSpcrTable (
     goto error_handler;\r
   }\r
 \r
+  // The SPCR InterfaceType uses the same encoding as that of the\r
+  // DBG2 table Port Subtype field. However InterfaceType is 8-bit\r
+  // while the Port Subtype field in the DBG2 table is 16-bit.\r
+  if ((SerialPortInfo->PortSubtype & 0xFF00) != 0) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "ERROR: SPCR: Invalid Port Sybtype (must be < 256). Status = %r\n",\r
+      Status\r
+      ));\r
+    goto error_handler;\r
+  }\r
+\r
   // Update the serial port subtype\r
-  AcpiSpcr.InterfaceType = SerialPortInfo->PortSubtype;\r
+  AcpiSpcr.InterfaceType = (UINT8)SerialPortInfo->PortSubtype;\r
 \r
   // Update the base address\r
   AcpiSpcr.BaseAddress.Address = SerialPortInfo->BaseAddress;\r