Patchwork Re: [PATCH] pci: fix pci_find_bus().

login
register
mail settings
Submitter Isaku Yamahata
Date April 9, 2010, 11:48 p.m.
Message ID <20100409234835.GA1232@valinux.co.jp>
Download mbox | patch
Permalink /patch/49878/
State New
Headers show

Comments

Isaku Yamahata - April 9, 2010, 11:48 p.m.
Oh I sent out the wrong one. This is the correct one.
Sorry for noise.

From 370c23c837070f78ca5715f032eacbf6747d42fb Mon Sep 17 00:00:00 2001
Message-Id: <370c23c837070f78ca5715f032eacbf6747d42fb.1270856742.git.yamahata@valinux.co.jp>
In-Reply-To: <cover.1270856742.git.yamahata@valinux.co.jp>
References: <cover.1270856742.git.yamahata@valinux.co.jp>
From: Isaku Yamahata <yamahata@valinux.co.jp>
Date: Fri, 9 Apr 2010 19:09:35 +0900
Subject: [PATCH] pci: fix pci_find_bus().

When looking down child bus, it should look parent bridge's
bus number, not child bus's.

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 |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Michael S. Tsirkin - April 11, 2010, 10:51 a.m.
On Sat, Apr 10, 2010 at 08:48:35AM +0900, Isaku Yamahata wrote:
> Oh I sent out the wrong one. This is the correct one.
> Sorry for noise.
> 
> >From 370c23c837070f78ca5715f032eacbf6747d42fb Mon Sep 17 00:00:00 2001
> Message-Id: <370c23c837070f78ca5715f032eacbf6747d42fb.1270856742.git.yamahata@valinux.co.jp>
> In-Reply-To: <cover.1270856742.git.yamahata@valinux.co.jp>
> References: <cover.1270856742.git.yamahata@valinux.co.jp>
> From: Isaku Yamahata <yamahata@valinux.co.jp>
> Date: Fri, 9 Apr 2010 19:09:35 +0900
> Subject: [PATCH] pci: fix pci_find_bus().
> 
> When looking down child bus, it should look parent bridge's
> bus number, not child bus's.
> 
> 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 |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 0dbca17..b6e6bbe 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1556,10 +1556,10 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num)
>      }
>  
>      /* 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]) ) {
> +    if (!bus->parent_dev /* pci host bridge */
> +        || (pci_bus_num(bus) <= bus_num &&

Better use PCI_SECONDARY_BUS here directly, we know parent_dev is
non-NULL.

> +            bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS])) {
> +        QLIST_FOREACH(sec, &bus->child, sibling) {
>              ret = pci_find_bus(sec, bus_num);
>              if (ret) {
>                  return ret;

What do you think about converting code to loop
as I suggested earlier?

> -- 
> 1.6.6.1
> 
> 
> -- 
> yamahata

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 0dbca17..b6e6bbe 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1556,10 +1556,10 @@  PCIBus *pci_find_bus(PCIBus *bus, int bus_num)
     }
 
     /* 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]) ) {
+    if (!bus->parent_dev /* pci host bridge */
+        || (pci_bus_num(bus) <= bus_num &&
+            bus_num <= bus->parent_dev->config[PCI_SUBORDINATE_BUS])) {
+        QLIST_FOREACH(sec, &bus->child, sibling) {
             ret = pci_find_bus(sec, bus_num);
             if (ret) {
                 return ret;