[PATCH V5 03/12] PCI: dwc: Allow external allocation of pci_host_bridge
From: Sherry Sun
Date: Thu Feb 12 2026 - 23:08:21 EST
Currently, dw_pcie_host_init() always allocates a new pci_host_bridge
structure internally using devm_pci_alloc_host_bridge(). This prevents
drivers from pre-allocating the bridge structure when needed.
Modify dw_pcie_host_init() to check if pp->bridge is already set. If
set, use the pre-allocated bridge instead of allocating a new one. This
maintains backward compatibility with existing drivers that don't set
pp->bridge, while allowing new drivers to pre-allocate when needed.
Signed-off-by: Sherry Sun <sherry.sun@xxxxxxx>
---
drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 6ae6189e9b8a..c2de9830e1e9 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -575,11 +575,15 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
raw_spin_lock_init(&pp->lock);
- bridge = devm_pci_alloc_host_bridge(dev, 0);
- if (!bridge)
- return -ENOMEM;
+ if (!pp->bridge) {
+ bridge = devm_pci_alloc_host_bridge(dev, 0);
+ if (!bridge)
+ return -ENOMEM;
- pp->bridge = bridge;
+ pp->bridge = bridge;
+ } else {
+ bridge = pp->bridge;
+ }
ret = dw_pcie_host_get_resources(pp);
if (ret)
--
2.37.1