Fix to prevent infinite loop in build_pci_path().
authorKevin O'Connor <kevin@koconnor.net>
Sat, 22 Jan 2011 15:53:08 +0000 (10:53 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 22 Jan 2011 15:53:08 +0000 (10:53 -0500)
Make sure the PCI path doesn't point to itself.

src/pci.c

index 45f210d8db0ebf9c0caeb3777f063a3ecf4659eb..944a39309d493abaae95d7c34d15c832a53c6da6 100644 (file)
--- a/src/pci.c
+++ b/src/pci.c
@@ -194,7 +194,7 @@ pci_path_setup(void)
     PCIpaths = malloc_tmp(sizeof(*PCIpaths) * 256);
     if (!PCIpaths)
         return;
-    memset(PCIpaths, 0, sizeof(PCIpaths));
+    memset(PCIpaths, 0, sizeof(*PCIpaths) * 256);
 
     int roots = 0;
     int bdf, max;
@@ -209,7 +209,8 @@ pci_path_setup(void)
         if (v == PCI_HEADER_TYPE_BRIDGE || v == PCI_HEADER_TYPE_CARDBUS) {
             v = pci_config_readl(bdf, PCI_PRIMARY_BUS);
             int childbus = (v >> 8) & 0xff;
-            PCIpaths[childbus] = bdf | PP_PCIBRIDGE;
+            if (childbus > bus)
+                PCIpaths[childbus] = bdf | PP_PCIBRIDGE;
         }
     }
 }