From 5f46eb2307dd6d4ea163b6899ded81e795780059 Mon Sep 17 00:00:00 2001 From: Nhi Pham Date: Mon, 21 Aug 2023 10:27:30 +0700 Subject: MdeModulePkg/PciBusDxe: Fix boot hang with faulty PCI Option ROM A faulty PCI device has the Option ROM image size set to 0. UEFI reads two headers PCI_EXPANSION_ROM_HEADER and PCI_DATA_STRUCTURE to get the Option ROM information. Because the image size is 0, the Option ROM header address never changes. As a result, UEFI keeps reading the same two headers definitely. This patch is intended to fix it. Cc: Jian J Wang Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Nhi Pham Reviewed-by: Liming Gao --- MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index 89f5f64101..bd5ace18f6 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -506,13 +506,13 @@ LoadOpRomImage ( Indicator = RomPcir->Indicator; RomImageSize = RomImageSize + RomPcir->ImageLength * 512; RomBarOffset = RomBarOffset + RomPcir->ImageLength * 512; - } while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize)); + } while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize) && (RomImageSize > 0)); // // Some Legacy Cards do not report the correct ImageLength so used the maximum // of the legacy length and the PCIR Image Length // - if (CodeType == PCI_CODE_TYPE_PCAT_IMAGE) { + if ((RomImageSize > 0) && (CodeType == PCI_CODE_TYPE_PCAT_IMAGE)) { RomImageSize = MAX (RomImageSize, LegacyImageLength); } -- cgit v1.2.3