summaryrefslogtreecommitdiffstats
path: root/DynamicTablesPkg
diff options
context:
space:
mode:
authorSami Mujawar <sami.mujawar@arm.com>2019-07-09 11:56:14 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-03-29 16:53:35 +0000
commit869f234140fd9b11ad9b77fd071164e4be873fb0 (patch)
treec68c648d297001e70cc546433f75d1c32a3baf60 /DynamicTablesPkg
parent3e025c77429c2f92cecf6045854808ddcacfdf6d (diff)
downloadedk2-869f234140fd9b11ad9b77fd071164e4be873fb0.tar.gz
edk2-869f234140fd9b11ad9b77fd071164e4be873fb0.tar.bz2
edk2-869f234140fd9b11ad9b77fd071164e4be873fb0.zip
DynamicTablesPkg: Fix serial port subtype warning
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>
Diffstat (limited to 'DynamicTablesPkg')
-rw-r--r--DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c
index 1404279f82..4b2580da7d 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c
@@ -217,8 +217,21 @@ BuildSpcrTable (
goto error_handler;
}
+ // The SPCR InterfaceType uses the same encoding as that of the
+ // DBG2 table Port Subtype field. However InterfaceType is 8-bit
+ // while the Port Subtype field in the DBG2 table is 16-bit.
+ if ((SerialPortInfo->PortSubtype & 0xFF00) != 0) {
+ Status = EFI_INVALID_PARAMETER;
+ DEBUG ((
+ DEBUG_ERROR,
+ "ERROR: SPCR: Invalid Port Sybtype (must be < 256). Status = %r\n",
+ Status
+ ));
+ goto error_handler;
+ }
+
// Update the serial port subtype
- AcpiSpcr.InterfaceType = SerialPortInfo->PortSubtype;
+ AcpiSpcr.InterfaceType = (UINT8)SerialPortInfo->PortSubtype;
// Update the base address
AcpiSpcr.BaseAddress.Address = SerialPortInfo->BaseAddress;