From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.10580.1679697083676137417 for ; Fri, 24 Mar 2023 15:31:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=bGKLqsnp; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 6EED420FC4E8; Fri, 24 Mar 2023 15:31:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6EED420FC4E8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679697081; bh=iHrl9t5PoEIkTaFg6md8aSvAMwWx/Ya73EEoOf2cxmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bGKLqsnpK4xioe8UcZ1WKZdxXrkBl2/tmimHZpRB4tlKIzkw6FyBmItdpD8p6Nukw ODNCSH89xXAQjZBMKgHldd1e82+DSsztTKlfXmX6tlHyqSYOu7fi2yMBHFF+A4nXgy FEMA0epIpqGa+Gd/TZbMgLoSBMeAdVmbf1pzngHM= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Eric Dong , Erich McMillan , Michael D Kinney , Michael Kubacki , Rahul Kumar , Ray Ni Subject: [PATCH v7 10/12] UefiCpuPkg: Fix conditionally uninitialized variables Date: Fri, 24 Mar 2023 18:30:32 -0400 Message-Id: <20230324223034.1560-11-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.40.0.windows.1 In-Reply-To: <20230324223034.1560-1-mikuback@linux.microsoft.com> References: <20230324223034.1560-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Fixes CodeQL alerts for CWE-457: https://cwe.mitre.org/data/definitions/457.html Cc: Eric Dong Cc: Erich McMillan Cc: Michael D Kinney Cc: Michael Kubacki Cc: Rahul Kumar Cc: Ray Ni Co-authored-by: Erich McMillan Signed-off-by: Michael Kubacki Reviewed-by: Michael D Kinney --- UefiCpuPkg/CpuMpPei/CpuBist.c | 8 +++++++- UefiCpuPkg/CpuMpPei/CpuMpPei.c | 8 +++++++- UefiCpuPkg/CpuMpPei/CpuPaging.c | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuBist.c b/UefiCpuPkg/CpuMpPei/CpuBist.= c index 7dc93cd784d4..78e008703993 100644 --- a/UefiCpuPkg/CpuMpPei/CpuBist.c +++ b/UefiCpuPkg/CpuMpPei/CpuBist.c @@ -175,7 +175,13 @@ CollectBistDataFromPpi ( EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2; EFI_SEC_PLATFORM_INFORMATION_CPU *CpuInstanceInHob; =20 - MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledP= rocessors); + Status =3D MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &Numbe= rOfEnabledProcessors); + ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + NumberOfProcessors =3D 1; + NumberOfEnabledProcessors =3D 1; + } =20 BistInformationSize =3D sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) = + sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * Numb= erOfProcessors; diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPe= i.c index e7f1fe9f426c..b504bea3cfeb 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c @@ -473,7 +473,13 @@ InitializeMpExceptionStackSwitchHandlers ( return; } =20 - MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL); + Status =3D MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL); + ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + NumberOfProcessors =3D 1; + } + SwitchStackData =3D AllocatePages (EFI_SIZE_TO_PAGES (NumberOfProcesso= rs * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT))); ASSERT (SwitchStackData !=3D NULL); ZeroMem (SwitchStackData, NumberOfProcessors * sizeof (EXCEPTION_STACK= _SWITCH_CONTEXT)); diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPag= ing.c index 135422225340..a471f089c8ae 100644 --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c @@ -538,6 +538,7 @@ SetupStackGuardPage ( UINTN NumberOfProcessors; UINTN Bsp; UINTN Index; + EFI_STATUS Status; =20 // // One extra page at the bottom of the stack is needed for Guard page. @@ -547,7 +548,13 @@ SetupStackGuardPage ( ASSERT (FALSE); } =20 - MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL); + Status =3D MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL); + ASSERT_EFI_ERROR (Status); + + if (EFI_ERROR (Status)) { + NumberOfProcessors =3D 1; + } + MpInitLibWhoAmI (&Bsp); for (Index =3D 0; Index < NumberOfProcessors; ++Index) { StackBase =3D 0; --=20 2.40.0.windows.1