* [PATCH] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property
@ 2026-10-03 7:35 Marek Vasut
2026-10-05 23:37 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Marek Vasut @ 2026-10-03 7:35 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. Do the IO and MEM counting early to avoid controller
configuration rollback in case of failure.
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
---
drivers/pci/controller/pcie-rcar-host.c | 31 +++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/pci/controller/pcie-rcar-host.c b/drivers/pci/controller/pcie-rcar-host.c
index cd9171eebc289..4bcc8c3051ac4 100644
--- a/drivers/pci/controller/pcie-rcar-host.c
+++ b/drivers/pci/controller/pcie-rcar-host.c
@@ -341,6 +341,32 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
(macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5");
}
+static int rcar_pcie_validate_resource_count(struct rcar_pcie_host *host)
+{
+ struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
+ struct rcar_pcie *pcie = &host->pcie;
+ struct resource_entry *win;
+ int i = 0;
+
+ resource_list_for_each_entry(win, &bridge->windows) {
+ struct resource *res = win->res;
+ unsigned long type = resource_type(res);
+
+ if (!res->flags)
+ continue;
+
+ if (type == IORESOURCE_IO || type == IORESOURCE_MEM)
+ i++;
+
+ 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);
+ }
+
+ return 0;
+}
+
static void rcar_pcie_hw_enable(struct rcar_pcie_host *host)
{
struct rcar_pcie *pcie = &host->pcie;
@@ -947,6 +973,11 @@ static int rcar_pcie_probe(struct platform_device *pdev)
host = pci_host_bridge_priv(bridge);
pcie = &host->pcie;
pcie->dev = dev;
+
+ err = rcar_pcie_validate_resource_count(host);
+ if (err)
+ return err;
+
platform_set_drvdata(pdev, host);
for (i = 0; i < ARRAY_SIZE(rcar_pcie_supplies); i++) {
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property
2026-10-03 7:35 [PATCH] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property Marek Vasut
@ 2026-10-05 23:37 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2026-10-05 23:37 UTC (permalink / raw)
To: Marek Vasut
Cc: linux-pci, Krzysztof Wilczyński, Bjorn Helgaas,
Geert Uytterhoeven, Lad Prabhakar, Lorenzo Pieralisi,
Magnus Damm, Manivannan Sadhasivam, Rob Herring,
Yoshihiro Shimoda, linux-kernel, linux-renesas-soc
On Sat, Oct 03, 2026 at 09:35:59AM +0200, Marek Vasut wrote:
> 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. Do the IO and MEM counting early to avoid controller
> configuration rollback in case of failure.
>
> 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
> ---
> drivers/pci/controller/pcie-rcar-host.c | 31 +++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/drivers/pci/controller/pcie-rcar-host.c b/drivers/pci/controller/pcie-rcar-host.c
> index cd9171eebc289..4bcc8c3051ac4 100644
> --- a/drivers/pci/controller/pcie-rcar-host.c
> +++ b/drivers/pci/controller/pcie-rcar-host.c
> @@ -341,6 +341,32 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
> (macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5");
> }
>
> +static int rcar_pcie_validate_resource_count(struct rcar_pcie_host *host)
> +{
> + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(host);
> + struct rcar_pcie *pcie = &host->pcie;
> + struct resource_entry *win;
> + int i = 0;
> +
> + resource_list_for_each_entry(win, &bridge->windows) {
> + struct resource *res = win->res;
> + unsigned long type = resource_type(res);
> +
> + if (!res->flags)
> + continue;
> +
> + if (type == IORESOURCE_IO || type == IORESOURCE_MEM)
> + i++;
> +
> + 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);
> + }
> +
> + return 0;
> +}
> +
> static void rcar_pcie_hw_enable(struct rcar_pcie_host *host)
> {
> struct rcar_pcie *pcie = &host->pcie;
> @@ -947,6 +973,11 @@ static int rcar_pcie_probe(struct platform_device *pdev)
> host = pci_host_bridge_priv(bridge);
> pcie = &host->pcie;
> pcie->dev = dev;
> +
> + err = rcar_pcie_validate_resource_count(host);
> + if (err)
> + return err;
I guess you did this here to avoid rolling back controller config, but
the code would be a lot more readable if it checked the index at the
point where it might exceed the array bound, e.g., (I think) in
rcar_pcie_set_outbound().
This is for an invalid DT, which is unlikely. What if
rcar_pcie_set_outbound() just printed a warning and ignored any excess
windows?
> platform_set_drvdata(pdev, host);
>
> for (i = 0; i < ARRAY_SIZE(rcar_pcie_supplies); i++) {
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-05 23:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-03 7:35 [PATCH] PCI: rcar-host: Validate IO/MEM resource count in DT ranges property Marek Vasut
2026-10-05 23:37 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®