From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [121.200.0.92]) by mx.groups.io with SMTP id smtpd.web10.9616.1659835410687462376 for ; Sat, 06 Aug 2022 18:23:31 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: djc.id.au, ip: 121.200.0.92, mailfrom: dan@djc.id.au) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 12E2D10028D for ; Sun, 7 Aug 2022 11:23:27 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OzPSUHgfvYZe for ; Sun, 7 Aug 2022 11:23:27 +1000 (AEST) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 0B1A5100319; Sun, 7 Aug 2022 11:23:27 +1000 (AEST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on smtp01.aussiebb.com.au X-Spam-Level: ** X-Spam-Status: No, score=2.4 required=10.0 tests=FORGED_SPF_HELO, KHOP_HELO_FCRDNS,RDNS_DYNAMIC,SPF_HELO_PASS autolearn=disabled version=3.4.4 Received: from djc.id.au (159-196-107-41.9fc46b.syd.nbn.aussiebb.net [159.196.107.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp01.aussiebb.com.au (Postfix) with ESMTPS id DD19610028D for ; Sun, 7 Aug 2022 11:23:26 +1000 (AEST) Received: by djc.id.au (Postfix, from userid 1000) id 9E6338D496B; Sun, 7 Aug 2022 11:23:26 +1000 (AEST) Received: by djc.id.au (Postfix, from userid 1000) id DAA1E8D48F4; Sun, 7 Aug 2022 11:16:45 +1000 (AEST) From: "Dan Callaghan" To: devel@edk2.groups.io Cc: Jon Nettleton , Leif Lindholm , Meenakshi Aggarwal , Dan Callaghan Subject: [edk2-platform][PATCH] Silicon/NXP: avoid integer overflow when computing Serdes protocol map Date: Sun, 7 Aug 2022 11:16:37 +1000 Message-Id: <20220807011637.929232-1-djc@djc.id.au> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- 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/Sili= con/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=0D GetSerDesProtocolMap (&SerDesProtocolMap);=0D =0D - return (SerDesProtocolMap & (BIT0 << (PcieNum))) !=3D 0;=0D + return (SerDesProtocolMap & ((UINT64) BIT0 << (PcieNum))) !=3D 0;=0D }=0D =0D /**=0D diff --git a/Silicon/NXP/Library/SerDesHelperLib/SerDesHelperLib.c b/Silico= n/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", LaneProtoc= ol));=0D return EFI_NO_MAPPING;=0D }=0D - *SerDesProtocolMap |=3D (BIT0 << (LaneProtocol));=0D + *SerDesProtocolMap |=3D ((UINT64) BIT0 << (LaneProtocol));=0D }=0D =0D return EFI_SUCCESS;=0D --=20 2.36.0