[PATCH V7 02/13] PCI: host-generic: Add common helpers for parsing Root Port properties

Frank Li Frank.Li at nxp.com
Tue Mar 10 11:28:53 PDT 2026


From: Frank Li (AI-BOT) <frank.li at nxp.com>

> +int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *bridge)
> +{
> +	int ret = -ENOENT;
> +
> +	for_each_available_child_of_node_scoped(dev->of_node, of_port) {
> +		if (!of_node_is_type(of_port, "pci"))
> +			continue;
> +		ret = pci_host_common_parse_port(dev, bridge, of_port);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return ret;
> +}

AI: Returning -ENOENT when no ports are found may be unexpected by callers.
Consider whether this should return 0 (success, zero ports parsed) or if
callers must explicitly handle -ENOENT. Document the semantics clearly.

> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index bccc7a4bdd79..9cc3f4ebb370 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -647,6 +647,7 @@ static void pci_release_host_bridge_dev(struct device *dev)
>
>  	pci_free_resource_list(&bridge->windows);
>  	pci_free_resource_list(&bridge->dma_ranges);
> +	pci_free_resource_list(&bridge->ports);

AI: pci_free_resource_list() expects struct resource_entry nodes. The ports
list contains struct pci_host_port nodes. This will corrupt memory or
crash. Use list_for_each_entry_safe() with proper cleanup, or define a
dedicated pci_free_host_ports() function.


Frank



More information about the linux-arm-kernel mailing list