mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Angel J <iamanaws@httpd.dev>
Cc: linux-pci@vger.kernel.org, bhelgaas@google.com, robh@kernel.org,
	herve.codina@bootlin.com, lizhi.hou@amd.com,
	andrea.porta@suse.com, florian.fainelli@broadcom.com,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	regressions@lists.linux.dev,
	linux-rpi-kernel@lists.infradead.org
Subject: [PATCH v3] PCI: of_property: Omit bus properties without a subordinate bus
Date: Fri, 18 Sep 2026 14:55:40 -0500	[thread overview]
Message-ID: <20260918195540.GA1187209@bhelgaas> (raw)
In-Reply-To: <20260916145045.GA922158@bhelgaas>

Author: Angel J <iamanaws@httpd.dev>

PCI: of_property: Omit bus properties without a subordinate bus

A bridge (a device with a Type 1 header) may not have a secondary bus
allocated (pdev->subordinate), e.g., if there are no available bus numbers
or the bridge secondary/subordinate bus numbers are not writable.

The dynamic OF helpers of_pci_prop_bus_range() and of_pci_prop_intr_map()
dereference pdev->subordinate without checking it.  When
CONFIG_PCI_DYNAMIC_OF_NODES is enabled, this can cause a NULL pointer
dereference and early boot hang.

Generate 'bus-range' and 'interrupt-map' properties only when a subordinate
bus exists.  Keep the node and its remaining properties for bridges without
one.

The problem was latent since 407d1a51921e ("PCI: Create device tree node
for bridge"), but wasn't reachable until 1f340724419e ("PCI: of: Create
device tree PCI host bridge node"), which appeared in v6.15.  Before
1f340724419e, of_pci_make_dev_node() returned early because the parent OF
node was missing.

Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Signed-off-by: Angel J <iamanaws@httpd.dev>
[bhelgaas: move pdev->subordinate test to callees, commit log]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable@vger.kernel.org	# v6.6+
Link: https://patch.msgid.link/20260912043106.10715-1-iamanaws@httpd.dev
---
Changes in v3:
- Move pdev->subordinate tests to of_pci_prop_bus_range() and
  of_pci_prop_intr_map()

Changes in v2
(https://lore.kernel.org/all/20260912043106.10715-1-iamanaws@httpd.dev):
- Keep the dynamic OF node and skip only bus-range and interrupt-map
  when no subordinate bus exists, following review of v1.
- Tested on Linux 6.18.44 with the v1 guard removed.

v1
(https://lore.kernel.org/all/20260911230420.26244-1-iamanaws@httpd.dev)

diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c
index 75a358f73e69..1500740cc55d 100644
--- a/drivers/pci/of_property.c
+++ b/drivers/pci/of_property.c
@@ -95,9 +95,13 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
 				 struct of_changeset *ocs,
 				 struct device_node *np)
 {
-	u32 bus_range[] = { pdev->subordinate->busn_res.start,
-			    pdev->subordinate->busn_res.end };
+	u32 bus_range[2];
 
+	if (!pdev->subordinate)
+		return 0;
+
+	bus_range[0] = pdev->subordinate->busn_res.start;
+	bus_range[1] = pdev->subordinate->busn_res.end;
 	return of_changeset_add_prop_u32_array(ocs, np, "bus-range", bus_range,
 					       ARRAY_SIZE(bus_range));
 }
@@ -220,6 +224,9 @@ static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs,
 	int ret;
 	u8 pin;
 
+	if (!pdev->subordinate)
+		return 0;
+
 	pnode = pci_device_to_OF_node(pdev->bus->self);
 	if (!pnode)
 		pnode = pci_bus_to_OF_node(pdev->bus);

  reply	other threads:[~2026-09-18 19:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-23  2:14 [REGRESSION] PCI: Dynamic OF node creation hangs on invalid bridge configuration Angel J
2026-09-01  0:59 ` Angel J
2026-09-01  6:07   ` Thorsten Leemhuis
2026-09-03 23:17 ` Bjorn Helgaas
2026-09-04  8:57   ` Herve Codina
2026-09-09 11:27     ` Andrea della Porta
2026-09-11 23:01 ` Angel J
2026-09-11 23:04   ` [PATCH] PCI: of: Skip dynamic nodes for bridges without a subordinate bus Angel J
2026-09-12  4:31     ` [PATCH v2] PCI: of_property: Omit bus properties " Angel J
2026-09-16 14:50       ` Bjorn Helgaas
2026-09-18 19:55         ` Bjorn Helgaas [this message]
2026-09-18 20:20           ` [PATCH v3] " Bjorn Helgaas
2026-09-18 20:24             ` Angel J
2026-09-14 11:53   ` [REGRESSION] PCI: Dynamic OF node creation hangs on invalid bridge configuration Andrea della Porta
2026-09-14 22:05     ` Angel J
2026-09-14 23:28       ` Angel J
2026-09-15 10:30         ` Andrea della Porta
2026-09-16  1:21         ` Bjorn Helgaas
2026-09-16 11:14           ` Angel J
2026-09-16 14:42             ` Bjorn Helgaas
2026-09-16 19:28             ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918195540.GA1187209@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=andrea.porta@suse.com \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=herve.codina@bootlin.com \
    --cc=iamanaws@httpd.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=lizhi.hou@amd.com \
    --cc=regressions@lists.linux.dev \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®