[PATCH 04/15] PCI: Consistently use Header Type to detect bridge headers
From: Ilpo Järvinen
Date: Tue Dec 01 2026 - 11:00:03 EST
The Header Type decides the layout of the config space. A Type 0 header
is used by endpoints and a Type 1 header by bridges, which have the
bridge window registers. Earlier, Type 2 was also used for CardBus
bridges. The Class Code only describes the function of the device.
Commit b2fb5cc57469 ("PCI: Rely on config space header type, not class
code") converted bridge window sizing and assignment to use the Header
Type, but __pci_bridge_assign_resources(), pci_claim_bridge_resource()
and pci_bus_release_bridge_resources() still use the Class Code to
detect bridges. Using an inconsistent classifier creates corner cases
in programming, claiming, and releasing the bridge windows of Type 1
bridges whose Class Code is not PCI_CLASS_BRIDGE_PCI.
Consistently use the Header Type to detect bridges also in those
functions. If filtering out Type 1 devices with an unexpected Class Code
is desirable, it should be done in pci_setup_device() which already
does similar filtering for the other Header Types.
Fixes: b2fb5cc57469 ("PCI: Rely on config space header type, not class code")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
This patch supercedes the change in the cardbus series:
https://lore.kernel.org/linux-pci/20261109210714.3862-3-ilpo.jarvinen@xxxxxxxxxxxxxxx/
drivers/pci/setup-bus.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ea0039fb6ad0..c1033191571c 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -948,7 +948,7 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
if (pci_claim_resource(bridge, i) == 0)
return 0; /* Claimed the window */
- if ((bridge->class >> 8) != PCI_CLASS_BRIDGE_PCI)
+ if (bridge->hdr_type != PCI_HEADER_TYPE_BRIDGE)
return 0;
if (i > PCI_BRIDGE_PREF_MEM_WINDOW)
@@ -1636,12 +1636,12 @@ static void __pci_bridge_assign_resources(struct pci_dev *bridge,
__pci_bus_assign_resources(b, add_list, fail_head);
- switch (bridge->class >> 8) {
- case PCI_CLASS_BRIDGE_PCI:
+ switch (bridge->hdr_type) {
+ case PCI_HEADER_TYPE_BRIDGE:
pci_setup_bridge(b);
break;
- case PCI_CLASS_BRIDGE_CARDBUS:
+ case PCI_HEADER_TYPE_CARDBUS:
pci_setup_cardbus_bridge(b);
break;
@@ -1701,7 +1701,7 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus,
is_leaf_bridge = false;
- if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
+ if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE)
continue;
if (rel_type != whole_subtree)
@@ -1718,7 +1718,7 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus,
if (pci_is_root_bus(bus))
return;
- if ((bus->self->class >> 8) != PCI_CLASS_BRIDGE_PCI)
+ if (bus->self->hdr_type != PCI_HEADER_TYPE_BRIDGE)
return;
if ((rel_type == whole_subtree) || is_leaf_bridge)
--
2.47.3