From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4H6Y-0007NP-C9 for qemu-devel@nongnu.org; Tue, 20 Apr 2010 13:19:22 -0400 Received: from [140.186.70.92] (port=44792 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4H6V-0007L9-4y for qemu-devel@nongnu.org; Tue, 20 Apr 2010 13:19:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4H6S-00038m-R9 for qemu-devel@nongnu.org; Tue, 20 Apr 2010 13:19:18 -0400 Received: from mail-pv0-f173.google.com ([74.125.83.173]:61431) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4H6R-00037y-G1 for qemu-devel@nongnu.org; Tue, 20 Apr 2010 13:19:16 -0400 Received: by pva4 with SMTP id 4so162924pva.4 for ; Tue, 20 Apr 2010 10:19:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20100412025859.GD1232@valinux.co.jp> References: <20100409101324.GC14603@valinux.co.jp> <20100409234835.GA1232@valinux.co.jp> <20100411105129.GC8992@redhat.com> <20100412025859.GD1232@valinux.co.jp> Date: Tue, 20 Apr 2010 20:19:14 +0300 Message-ID: From: Blue Swirl Content-Type: text/plain; charset=UTF-8 Subject: [Qemu-devel] Re: [PATCH v2] pci: fix pci_find_bus(). List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" Thanks, applied. On 4/12/10, Isaku Yamahata 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 > Cc: "Michael S. Tsirkin" > Signed-off-by: Isaku Yamahata > --- > > 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 > > >