Message ID | 20100412025859.GD1232@valinux.co.jp |
---|---|
State | New |
Headers | show |
Thanks, applied. On 4/12/10, Isaku Yamahata <yamahata@valinux.co.jp> wrote: > When looking down child bus, it should look parent bridge's > bus number, not child bus's. > > Optimized tail recursion and style fix. > > > Cc: Blue Swirl <blauwirbel@gmail.com> > Cc: "Michael S. Tsirkin" <mst@redhat.com> > Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> > --- > > hw/pci.c | 25 ++++++++++++++++--------- > 1 files changed, 16 insertions(+), 9 deletions(-) > > > diff --git a/hw/pci.c b/hw/pci.c > > index 2355232..6c0cc7b 100644 > > --- a/hw/pci.c > +++ b/hw/pci.c > > @@ -1546,23 +1546,30 @@ static void pci_bridge_write_config(PCIDevice *d, > > > PCIBus *pci_find_bus(PCIBus *bus, int bus_num) > > { > - PCIBus *sec, *ret; > + PCIBus *sec; > > > - if (!bus) > + if (!bus) { > return NULL; > + } > > > if (pci_bus_num(bus) == bus_num) { > return bus; > > } > > /* try child bus */ > - QLIST_FOREACH(sec, &bus->child, sibling) { > - if (!bus->parent_dev /* pci host bridge */ > - || (pci_bus_num(sec) <= bus_num && > - bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS]) ) { > > - ret = pci_find_bus(sec, bus_num); > - if (ret) { > - return ret; > + if (!bus->parent_dev /* host pci bridge */ || > + (bus->parent_dev->config[PCI_SECONDARY_BUS] < bus_num && > > + bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS])) { > > + for (; bus; bus = sec) { > > + QLIST_FOREACH(sec, &bus->child, sibling) { > > + assert(sec->parent_dev); > + if (sec->parent_dev->config[PCI_SECONDARY_BUS] == bus_num) { > + return sec; > + } > + if (sec->parent_dev->config[PCI_SECONDARY_BUS] < bus_num && > > + bus_num <= sec->parent_dev->config[PCI_SUBORDINATE_BUS]) { > + break; > + } > } > } > } > > -- > 1.6.6.1 > > >
diff --git a/hw/pci.c b/hw/pci.c index 2355232..6c0cc7b 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1546,23 +1546,30 @@ static void pci_bridge_write_config(PCIDevice *d, PCIBus *pci_find_bus(PCIBus *bus, int bus_num) { - PCIBus *sec, *ret; + PCIBus *sec; - if (!bus) + if (!bus) { return NULL; + } if (pci_bus_num(bus) == bus_num) { return bus; } /* try child bus */ - QLIST_FOREACH(sec, &bus->child, sibling) { - if (!bus->parent_dev /* pci host bridge */ - || (pci_bus_num(sec) <= bus_num && - bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS]) ) { - ret = pci_find_bus(sec, bus_num); - if (ret) { - return ret; + if (!bus->parent_dev /* host pci bridge */ || + (bus->parent_dev->config[PCI_SECONDARY_BUS] < bus_num && + bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS])) { + for (; bus; bus = sec) { + QLIST_FOREACH(sec, &bus->child, sibling) { + assert(sec->parent_dev); + if (sec->parent_dev->config[PCI_SECONDARY_BUS] == bus_num) { + return sec; + } + if (sec->parent_dev->config[PCI_SECONDARY_BUS] < bus_num && + bus_num <= sec->parent_dev->config[PCI_SUBORDINATE_BUS]) { + break; + } } } }
When looking down child bus, it should look parent bridge's bus number, not child bus's. Optimized tail recursion and style fix. Cc: Blue Swirl <blauwirbel@gmail.com> Cc: "Michael S. Tsirkin" <mst@redhat.com> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp> --- hw/pci.c | 25 ++++++++++++++++--------- 1 files changed, 16 insertions(+), 9 deletions(-)