[PATCH 3/4] pci: add pci_is_bridge() helper

Bjorn Helgaas helgaas at kernel.org
Thu May 21 09:23:55 PDT 2026


On Thu, May 21, 2026 at 10:36:57AM +0200, Sascha Hauer wrote:
> Mirror the Linux helper of the same name so callers don't have to
> open-code the header-type compare.
> 
> Replace the open-coded site in pci_ea_init().
> 
> Assisted-by: Claude Opus 4.7
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/pci/pci.c   |  2 +-
>  include/linux/pci.h | 14 ++++++++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 8d18889109..fc00ec2249 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -334,7 +334,7 @@ static void pci_ea_init(struct pci_dev *dev)
>  	offset = ea + PCI_EA_FIRST_ENT;
>  
>  	/* Skip DWORD 2 for type 1 functions */
> -	if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE)
> +	if (pci_is_bridge(dev))
>  		offset += 4;
>  
>  	/* parse each EA entry */
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index f6511e0095..a2dbaf6ec2 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -123,6 +123,20 @@ struct pci_dev {
>  };
>  #define	to_pci_dev(d) container_of(d, struct pci_dev, dev)
>  
> +/**
> + * pci_is_bridge - check if the PCI device is a bridge
> + * @dev: PCI device
> + *
> + * Return true if the PCI device is a bridge of PCI-to-PCI type. Masks the
> + * multi-function flag so a multi-function bridge is still recognised.
> + */
> +static inline bool pci_is_bridge(struct pci_dev *dev)
> +{
> +	u8 type = dev->hdr_type & PCI_HEADER_TYPE_MASK;
> +
> +	return type == PCI_HEADER_TYPE_BRIDGE;
> +}

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/pci.h?id=v7.0#n755

Am I missing something?

>  #define pci_resource_start(dev, bar)	((dev)->resource[(bar)].start)
>  #define pci_resource_end(dev, bar)	((dev)->resource[(bar)].end)
>  #define pci_resource_flags(dev, bar)	((dev)->resource[(bar)].flags)
> 
> -- 
> 2.47.3
> 
> 
> 



More information about the barebox mailing list