PCI: Fix calculation of bridge window's size and alignment
authorYongji Xie <elohimes@gmail.com>
Mon, 10 Apr 2017 11:58:11 +0000 (19:58 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 18 Apr 2017 19:47:20 +0000 (14:47 -0500)
In case that one device's alignment is greater than its size, we may
get an incorrect size and alignment for its bus's memory window in
pbus_size_mem().  Fix this case.

Signed-off-by: Yongji Xie <elohimes@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/setup-bus.c

index cb389277df413915e5784f1c18bea599dc90fca8..958da7db90331c44315f95ab90553c586d918c46 100644 (file)
@@ -1066,10 +1066,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
                                r->flags = 0;
                                continue;
                        }
-                       size += r_size;
+                       size += max(r_size, align);
                        /* Exclude ranges with size > align from
                           calculation of the alignment. */
-                       if (r_size == align)
+                       if (r_size <= align)
                                aligns[order] += align;
                        if (order > max_order)
                                max_order = order;