[PATCH 03/11] PCI: Use Header Type to detect CardBus bridges in pci_resource_alignment()
From: Ilpo Järvinen
Date: Mon Nov 09 2026 - 16:08:35 EST
pci_resource_alignment() detects CardBus bridges by the Class Code while
the rest of the PCI core uses the Header Type.
When CONFIG_CARDBUS is not set, pci_cardbus_resource_alignment() returns
zero. A non-CardBus device that reports the CardBus Class Code then gets
zero alignment for all its resources, and pbus_size_mem() calls __ffs()
on it, which is undefined behavior. When CARDBUS is set, the device gets
CardBus window alignment instead of its own alignment.
Use pci_is_cardbus_bridge() in pci_resource_alignment() and make it take
a const pointer as pci_resource_alignment() has one.
Fixes: fd29d4ea09ba ("PCI: Separate CardBus setup & build it only with CONFIG_CARDBUS")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
drivers/pci/pci.h | 2 +-
drivers/pci/setup-res.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..519918e24cc5 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -419,7 +419,7 @@ extern unsigned long pci_hotplug_mmio_size;
extern unsigned long pci_hotplug_mmio_pref_size;
extern unsigned long pci_hotplug_bus_size;
-static inline bool pci_is_cardbus_bridge(struct pci_dev *dev)
+static inline bool pci_is_cardbus_bridge(const struct pci_dev *dev)
{
return dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
}
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 376f09630a4a..d8d53861b4a6 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -255,7 +255,7 @@ resource_size_t pci_resource_alignment(const struct pci_dev *dev,
if (pci_resource_is_iov(resno))
return pci_sriov_resource_alignment(dev, resno);
- if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
+ if (pci_is_cardbus_bridge(dev))
return pci_cardbus_resource_alignment(res);
return resource_alignment(res);
}
--
2.47.3