RE: [PATCH V5 03/12] PCI: dwc: Allow external allocation of pci_host_bridge
From: Sherry Sun <hidden>
Date: 2026-02-24 10:34:21
Also in:
imx, linux-devicetree, linux-pci, lkml
Subject: Re: [PATCH V5 03/12] PCI: dwc: Allow external allocation of pci_host_bridge On Fri, Feb 13, 2026 at 10:29:12AM -0500, Frank Li wrote:quoted
On Fri, Feb 13, 2026 at 12:08:43PM +0800, Sherry Sun wrote:quoted
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-allocatingthe bridge structure when needed.quoted
quoted
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 <redacted> --- 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.cb/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);It'd better call parse port here, or in devm_pci_alloc_host_bridge().Agree. We should try to avoid calling devm_pci_alloc_host_bridge() from glue drivers. - Maniquoted
If that, needn't check pp->bridge.
Ok, thanks Frank and Mani for the suggestion here, will improve it in next version. Best Regards Sherry
quoted
Frankquoted
+ 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-- மணிவண்ணன் சதாசிவம்