Skip to content

Commit

Permalink
Merged PR 6024: CodeQL Fixes
Browse files Browse the repository at this point in the history
Resolves CodeQL issues.

Another lighter pass of CodeQL will occur shortly in the future.

- [ ] Breaking change?
  - Will this change break pre-existing builds or functionality without action being taken?
  **No**

- Verified CI build
- Checked before and after CodeQL results
- Verified boot on QemuQ35Pkg

N/A - If CodeQL was run before these changes, run again to get latest results

Co-authored-by: Aaron Pop <aaronpop@microsoft.com>
Co-authored-by: Kun Qin <kuqin@microsoft.com>
Co-authored-by: Oliver Smith-Denny <osde@microsoft.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>

Merged PR 6100: Updated boot manager code to register boot menu as before

The newly added check will bail the routine if there is no boot options available. This will make the boot menu option not being registered and thus change the boot order.

The fix was to check the returned boot options and if NULL is returned, the routine will continue to register the boot menu.

- [ ] Breaking change?
  - Will this change break pre-existing builds or functionality without action being taken?

Verified on virtual platforms that the boot menu is properly registered as before.

N/A
  • Loading branch information
makubacki authored and kenlautner committed May 9, 2023
1 parent 4debc5d commit 2998774
Show file tree
Hide file tree
Showing 65 changed files with 1,752 additions and 1,014 deletions.
5 changes: 4 additions & 1 deletion CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,10 @@ qsort (
// Use CRT-style malloc to cover BS and RT memory allocation.
//
Buffer = malloc (width);
ASSERT (Buffer != NULL);
if (Buffer == NULL) {
ASSERT (Buffer != NULL);
return;
}

//
// Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
Expand Down
6 changes: 5 additions & 1 deletion MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,11 @@ StartPciDevices (
LIST_ENTRY *CurrentLink;

RootBridge = GetRootBridgeByHandle (Controller);
ASSERT (RootBridge != NULL);
if (RootBridge == NULL) {
ASSERT (RootBridge != NULL);
return EFI_NOT_READY;
}

ThisHostBridge = RootBridge->PciRootBridgeIo->ParentHandle;

CurrentLink = mPciDevicePool.ForwardLink;
Expand Down
80 changes: 54 additions & 26 deletions MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,9 @@ GetMaxResourceConsumerDevice (
&& (Temp->ResourceUsage != PciResUsagePadding))
{
PPBResNode = GetMaxResourceConsumerDevice (Temp);
PciResNode = GetLargerConsumerDevice (PciResNode, PPBResNode);
if (PPBResNode != NULL) {
PciResNode = GetLargerConsumerDevice (PciResNode, PPBResNode);
}
} else {
PciResNode = GetLargerConsumerDevice (PciResNode, Temp);
}
Expand Down Expand Up @@ -1409,7 +1411,7 @@ PciBridgeEnumerator (
}

Status = PciBridgeResourceAllocator (BridgeDev);

ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
return Status;
}
Expand Down Expand Up @@ -1437,11 +1439,11 @@ PciBridgeResourceAllocator (
IN PCI_IO_DEVICE *Bridge
)
{
PCI_RESOURCE_NODE *IoBridge;
PCI_RESOURCE_NODE *Mem32Bridge;
PCI_RESOURCE_NODE *PMem32Bridge;
PCI_RESOURCE_NODE *Mem64Bridge;
PCI_RESOURCE_NODE *PMem64Bridge;
PCI_RESOURCE_NODE *IoBridge = NULL;
PCI_RESOURCE_NODE *Mem32Bridge = NULL;
PCI_RESOURCE_NODE *PMem32Bridge = NULL;
PCI_RESOURCE_NODE *Mem64Bridge = NULL;
PCI_RESOURCE_NODE *PMem64Bridge = NULL;
UINT64 IoBase;
UINT64 Mem32Base;
UINT64 PMem32Base;
Expand All @@ -1457,6 +1459,9 @@ PciBridgeResourceAllocator (
PciBarTypeIo16,
PciResUsageTypical
);
if (IoBridge == NULL) {
goto CleanupAndExit;
}

Mem32Bridge = CreateResourceNode (
Bridge,
Expand All @@ -1466,6 +1471,9 @@ PciBridgeResourceAllocator (
PciBarTypeMem32,
PciResUsageTypical
);
if (Mem32Bridge == NULL) {
goto CleanupAndExit;
}

PMem32Bridge = CreateResourceNode (
Bridge,
Expand All @@ -1475,6 +1483,9 @@ PciBridgeResourceAllocator (
PciBarTypePMem32,
PciResUsageTypical
);
if (PMem32Bridge == NULL) {
goto CleanupAndExit;
}

Mem64Bridge = CreateResourceNode (
Bridge,
Expand All @@ -1484,6 +1495,9 @@ PciBridgeResourceAllocator (
PciBarTypeMem64,
PciResUsageTypical
);
if (Mem64Bridge == NULL) {
goto CleanupAndExit;
}

PMem64Bridge = CreateResourceNode (
Bridge,
Expand All @@ -1493,6 +1507,9 @@ PciBridgeResourceAllocator (
PciBarTypePMem64,
PciResUsageTypical
);
if (PMem64Bridge == NULL) {
goto CleanupAndExit;
}

//
// Create resourcemap by going through all the devices subject to this root bridge
Expand All @@ -1516,7 +1533,7 @@ PciBridgeResourceAllocator (
);

if (EFI_ERROR (Status)) {
return Status;
goto CleanupAndExit;
}

//
Expand Down Expand Up @@ -1559,17 +1576,32 @@ PciBridgeResourceAllocator (
PMem64Bridge
);

DestroyResourceTree (IoBridge);
DestroyResourceTree (Mem32Bridge);
DestroyResourceTree (PMem32Bridge);
DestroyResourceTree (PMem64Bridge);
DestroyResourceTree (Mem64Bridge);
CleanupAndExit:

if (IoBridge != NULL) {
DestroyResourceTree (IoBridge);
gBS->FreePool (IoBridge);
}

if (Mem32Bridge != NULL) {
DestroyResourceTree (Mem32Bridge);
gBS->FreePool (Mem32Bridge);
}

if (PMem32Bridge != NULL) {
DestroyResourceTree (PMem32Bridge);
gBS->FreePool (PMem32Bridge);
}

gBS->FreePool (IoBridge);
gBS->FreePool (Mem32Bridge);
gBS->FreePool (PMem32Bridge);
gBS->FreePool (PMem64Bridge);
gBS->FreePool (Mem64Bridge);
if (PMem64Bridge != NULL) {
DestroyResourceTree (PMem64Bridge);
gBS->FreePool (PMem64Bridge);
}

if (Mem64Bridge != NULL) {
DestroyResourceTree (Mem64Bridge);
gBS->FreePool (Mem64Bridge);
}

return EFI_SUCCESS;
}
Expand Down Expand Up @@ -2019,14 +2051,10 @@ PciHotPlugRequestNotify (
return EFI_INVALID_PARAMETER;
}

if (Operation == EfiPciHotPlugRequestAdd) {
if (ChildHandleBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
} else if ((Operation == EfiPciHotplugRequestRemove) && (*NumberOfChildren != 0)) {
if (ChildHandleBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
if ((Operation == EfiPciHotPlugRequestAdd) && (ChildHandleBuffer == NULL)) {
return EFI_INVALID_PARAMETER;
} else if ((Operation == EfiPciHotplugRequestRemove) && (*NumberOfChildren != 0) && (ChildHandleBuffer == NULL)) {
return EFI_INVALID_PARAMETER;
}

Status = gBS->OpenProtocol (
Expand Down
4 changes: 3 additions & 1 deletion MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,9 @@ SupportPaletteSnoopAttributes (
// Check if they are on the same bus
//
if (Temp->Parent == PciIoDevice->Parent) {
PCI_READ_COMMAND_REGISTER (Temp, &VGACommand);
if (EFI_ERROR (PCI_READ_COMMAND_REGISTER (Temp, &VGACommand))) {
return EFI_UNSUPPORTED;
}

//
// If they are on the same bus, either one can
Expand Down
33 changes: 31 additions & 2 deletions MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ DumpResourceMap (
}

ChildResources = AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildResourceCount);
if (ChildResources == NULL) {
return;
}

ASSERT (ChildResources != NULL);
ChildResourceCount = 0;
for (Index = 0; Index < ResourceCount; Index++) {
Expand Down Expand Up @@ -545,6 +549,9 @@ PciHostBridgeResourceAllocator (
PciBarTypeIo16,
PciResUsageTypical
);
if (IoBridge == NULL) {
return EFI_OUT_OF_RESOURCES;
}

Mem32Bridge = CreateResourceNode (
RootBridgeDev,
Expand All @@ -554,6 +561,10 @@ PciHostBridgeResourceAllocator (
PciBarTypeMem32,
PciResUsageTypical
);
if (Mem32Bridge == NULL) {
FreePool (IoBridge);
return EFI_OUT_OF_RESOURCES;
}

PMem32Bridge = CreateResourceNode (
RootBridgeDev,
Expand All @@ -563,6 +574,11 @@ PciHostBridgeResourceAllocator (
PciBarTypePMem32,
PciResUsageTypical
);
if (PMem32Bridge == NULL) {
FreePool (IoBridge);
FreePool (Mem32Bridge);
return EFI_OUT_OF_RESOURCES;
}

Mem64Bridge = CreateResourceNode (
RootBridgeDev,
Expand All @@ -572,6 +588,12 @@ PciHostBridgeResourceAllocator (
PciBarTypeMem64,
PciResUsageTypical
);
if (Mem64Bridge == NULL) {
FreePool (IoBridge);
FreePool (Mem32Bridge);
FreePool (PMem32Bridge);
return EFI_OUT_OF_RESOURCES;
}

PMem64Bridge = CreateResourceNode (
RootBridgeDev,
Expand All @@ -581,6 +603,13 @@ PciHostBridgeResourceAllocator (
PciBarTypePMem64,
PciResUsageTypical
);
if (PMem64Bridge == NULL) {
FreePool (IoBridge);
FreePool (Mem32Bridge);
FreePool (PMem32Bridge);
FreePool (Mem64Bridge);
return EFI_OUT_OF_RESOURCES;
}

//
// Get the max ROM size that the root bridge can process
Expand Down Expand Up @@ -1100,7 +1129,7 @@ PciScanBus (
EFI_HPC_STATE State;
UINT64 PciAddress;
EFI_HPC_PADDING_ATTRIBUTES Attributes;
VOID *DescriptorsBuffer = NULL; // MS_CHANGE
VOID *DescriptorsBuffer = NULL; // MS_CHANGE
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *NextDescriptors;
UINT16 BusRange;
Expand Down Expand Up @@ -1266,7 +1295,7 @@ PciScanBus (
return Status;
}

Descriptors = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)DescriptorsBuffer; // MS_CHANGE
Descriptors = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)DescriptorsBuffer; // MS_CHANGE
BusRange = 0;
NextDescriptors = Descriptors;
Status = PciGetBusRange (
Expand Down
4 changes: 3 additions & 1 deletion MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ ProcessOpRomImage (
EfiOpRomImageNode.EndingOffset = (UINTN)RomBarOffset + ImageSize - 1 - (UINTN)RomBar;

PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, &EfiOpRomImageNode.Header);
ASSERT (PciOptionRomImageDevicePath != NULL);
if (PciOptionRomImageDevicePath == NULL) {
return EFI_NOT_FOUND;
}

//
// load image and start image
Expand Down
Loading

0 comments on commit 2998774

Please sign in to comment.