Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property
@ 2026-10-17 17:18 Marek Vasut
  2026-10-17 17:24 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Vasut @ 2026-10-17 17:18 UTC (permalink / raw)
  To: linux-pci
  Cc: Marek Vasut, Krzysztof Wilczyński, Bjorn Helgaas,
	Geert Uytterhoeven, Lad Prabhakar, Lorenzo Pieralisi, Magnus Damm,
	Manivannan Sadhasivam, Rob Herring, Yoshihiro Shimoda,
	linux-kernel, linux-renesas-soc

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@mailbox.org>
---
Cc: "Krzysztof Wilczyński" <kwilczynski@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>
Cc: Magnus Damm <magnus.damm@gmail.com>
Cc: Manivannan Sadhasivam <mani@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org
---
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-17 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-17 17:18 [PATCH v2] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property Marek Vasut
2026-10-17 17:24 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox