[PATCH] pci_do_scan_bus

Jason Zebchuk (jason@consensys.com)
Tue, 13 Aug 2002 12:52:21 -0400


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

--- linux-2.5.30/drivers/pci/probe.c Thu Aug 1 17:16:10 2002
+++ linux/drivers/pci/probe.c Tue Aug 6 12:36:53 2002
@@ -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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/