[PATCH v2] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property

From: Marek Vasut

Date: Sat Oct 17 2026 - 13:36:36 EST


The R-Car Gen3 PCIEC controller supports up to 4 memory area mappings.
Count the IO and MEM ranges described in DT 'ranges' property of the
controller DT node, and in case there are more than 4, refuse to probe
the controller driver, because such DT does not describe valid hardware
configuration.

Fixes: 5d2917d469fa ("PCI: rcar: Convert to DT resource parsing API")
Signed-off-by: Marek Vasut <marek.vasut+renesas@xxxxxxxxxxx>
---
Cc: "Krzysztof Wilczyński" <kwilczynski@xxxxxxxxxx>
Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
Cc: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
Cc: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
Cc: Lorenzo Pieralisi <lpieralisi@xxxxxxxxxx>
Cc: Magnus Damm <magnus.damm@xxxxxxxxx>
Cc: Manivannan Sadhasivam <mani@xxxxxxxxxx>
Cc: Rob Herring <robh@xxxxxxxxxx>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@xxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-pci@xxxxxxxxxxxxxxx
Cc: linux-renesas-soc@xxxxxxxxxxxxxxx
---
V2: Perform the validation in rcar_pcie_hw_enable()
---
drivers/pci/controller/pcie-rcar-host.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-rcar-host.c b/drivers/pci/controller/pcie-rcar-host.c
index cd9171eebc289..5856861922599 100644
--- a/drivers/pci/controller/pcie-rcar-host.c
+++ b/drivers/pci/controller/pcie-rcar-host.c
@@ -341,7 +341,7 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
(macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5");
}

-static void rcar_pcie_hw_enable(struct rcar_pcie_host *host)
+static int rcar_pcie_hw_enable(struct rcar_pcie_host *host)
{
struct rcar_pcie *pcie = &host->pcie;
struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
@@ -358,6 +358,11 @@ static void rcar_pcie_hw_enable(struct rcar_pcie_host *host)
if (!res->flags)
continue;

+ if (i >= RCAR_PCI_MAX_RESOURCES)
+ return dev_err_probe(pcie->dev, -ENOSPC,
+ "Too many IO/MEM entries in DT 'ranges' property, limit is %d\n",
+ RCAR_PCI_MAX_RESOURCES);
+
switch (resource_type(res)) {
case IORESOURCE_IO:
case IORESOURCE_MEM:
@@ -366,13 +371,18 @@ static void rcar_pcie_hw_enable(struct rcar_pcie_host *host)
break;
}
}
+
+ return 0;
}

static int rcar_pcie_enable(struct rcar_pcie_host *host)
{
struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
+ int ret;

- rcar_pcie_hw_enable(host);
+ ret = rcar_pcie_hw_enable(host);
+ if (ret)
+ return ret;

pci_add_flags(PCI_REASSIGN_ALL_BUS);

--
2.53.0