public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platform][PATCH] Silicon/NXP: avoid integer overflow when computing Serdes protocol map
@ 2022-08-07  1:16 Dan Callaghan
  0 siblings, 0 replies; only message in thread
From: Dan Callaghan @ 2022-08-07  1:16 UTC (permalink / raw)
  To: devel; +Cc: Jon Nettleton, Leif Lindholm, Meenakshi Aggarwal, Dan Callaghan

SerDesProtocolMap is a UINT64, but BIT0 is an unadorned int. Shifting
BIT0 left by more than 31 bits is undefined behaviour. This would cause
SerDesProtocolMap to be filled with incorrect values when using Serdes
protocols numbered 32 and above, such as the SGMII protocols.

This fixes a hang at boot time on the Solidrun Honeycomb with SERDES
configuration 4_5_2.

Signed-off-by: Dan Callaghan <djc@djc.id.au>
---
 Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c | 2 +-
 Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 7f11d7a602..127eb3e175 100644
--- a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -748,7 +748,7 @@ IsPcieNumEnabled(
   // Reading serdes protocol map
   GetSerDesProtocolMap (&SerDesProtocolMap);
 
-  return (SerDesProtocolMap & (BIT0 << (PcieNum))) != 0;
+  return (SerDesProtocolMap & ((UINT64) BIT0 << (PcieNum))) != 0;
 }
 
 /**
diff --git a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c
index 1e8158541c..62a32d5caf 100644
--- a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c
+++ b/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c
@@ -157,7 +157,7 @@ GetSerDesMap (
       DEBUG ((DEBUG_ERROR, "Unknown SerDes lane protocol %d\n", LaneProtocol));
       return EFI_NO_MAPPING;
     }
-    *SerDesProtocolMap |= (BIT0 << (LaneProtocol));
+    *SerDesProtocolMap |= ((UINT64) BIT0 << (LaneProtocol));
   }
 
   return EFI_SUCCESS;
-- 
2.36.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-07  1:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-07  1:16 [edk2-platform][PATCH] Silicon/NXP: avoid integer overflow when computing Serdes protocol map Dan Callaghan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox