[PATCH V5 03/12] PCI: dwc: Allow external allocation of pci_host_bridge
Frank Li
Frank.li at nxp.com
Fri Feb 13 07:29:12 PST 2026
On Fri, Feb 13, 2026 at 12:08:43PM +0800, Sherry Sun wrote:
> 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 at nxp.com>
> ---
> 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);
It'd better call parse port here, or in devm_pci_alloc_host_bridge().
If that, needn't check pp->bridge.
Frank
> + 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
>
More information about the linux-arm-kernel
mailing list