]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI: dwc: ep: Ensure proper iteration over outbound map windows
authorFrank Li <Frank.Li@nxp.com>
Sat, 15 Mar 2025 20:15:46 +0000 (15:15 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 24 Mar 2025 19:58:34 +0000 (14:58 -0500)
Most systems' PCIe outbound map windows have non-zero physical addresses,
but the possibility of encountering zero increased after following commit
("PCI: dwc: Use parent_bus_offset").

'ep->outbound_addr[n]', representing 'parent_bus_address', might be 0 on
some hardware, which trims high address bits through bus fabric before
sending to the PCIe controller.

Replace the iteration logic with 'for_each_set_bit()' to ensure only
allocated map windows are iterated when determining the ATU index from a
given address.

Link: https://lore.kernel.org/r/20250315201548.858189-12-helgaas@kernel.org
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/controller/dwc/pcie-designware-ep.c

index bb87d0c5c665c08635a7aa4ec8b627f0eeae293e..2ef9964fa0808b559aee60a0eb7a0c4885905851 100644 (file)
@@ -282,7 +282,7 @@ static int dw_pcie_find_index(struct dw_pcie_ep *ep, phys_addr_t addr,
        u32 index;
        struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-       for (index = 0; index < pci->num_ob_windows; index++) {
+       for_each_set_bit(index, ep->ob_window_map, pci->num_ob_windows) {
                if (ep->outbound_addr[index] != addr)
                        continue;
                *atu_index = index;