Skip to contentSkip to conversation

pci_do_scan_bus

PATCH New Jason Zebchuk 1 participant 1 message Aug 13, 2002 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci_do_scan_bus

Hi Martin,

I've run into a stack overflow problem during boot that is caused by the
pci subsystem. The function pci_do_scan_bus() puts a pci_dev on the stack, and then indirectly calls itself recursively. While this doesn't usually cause any problems, the stack will overflow when there are a large number of cascaded pci buses.

This patch will fix the problem in the 2.5.30 kernel. I discovered the
problem in the 2.4.18 kernel, and for anyone who wants to patch that kernel, the same patch will work if you change "probe.c" to "pci.c"

Thanks,

Jason Zebchuk
Consensys RAIDZONE

drivers/pci/probe.c Tue Aug 6 12:36:53 2002 renamed from drivers/pci/probe.c Thu Aug 1 17:16:10 2002 +12 -8
@@ -497,23 +497,27 @@
 {
        unsigned int devfn, max, pass;
        struct list_head *ln;
-       struct pci_dev *dev, dev0;
+       struct pci_dev *dev, *dev0;
 
        DBG("Scanning bus %02x\n", bus->number);
        max = bus->secondary;
 
        /* Create a device template */
-       memset(&dev0, 0, sizeof(dev0));
-       dev0.bus = bus;
-       dev0.sysdata = bus->sysdata;
-       dev0.dev.parent = bus->dev;
-       dev0.dev.bus = &pci_bus_type;
+       dev0 = kmalloc(sizeof(struct pci_dev), GFP_ATOMIC);
+       if (dev0 == NULL)
+               BUG();
+       memset(dev0, 0, sizeof(dev0));
+       dev0->bus = bus;
+       dev0->sysdata = bus->sysdata;
+       dev0->dev.parent = bus->dev;
+       dev0->dev.bus = &pci_bus_type;
 
        /* Go find them, Rover! */
        for (devfn = 0; devfn < 0x100; devfn += 8) {
-               dev0.devfn = devfn;
-               pci_scan_slot(&dev0);
+               dev0->devfn = devfn;
+               pci_scan_slot(dev0);
        }
+       kfree(dev0);
 
        /*
         * After performing arch-dependent fixup of the bus, look behind