RE: [PATCH] PCI: hv: Don't use container_of() on non-vPCI buses in config block ops
From: Dexuan Cui
Date: Thu Dec 03 2026 - 22:31:02 EST
> From: Hamza Mahfooz <hamzamahfooz@xxxxxxxxxxxxxxxxxxx>
> Sent: Thursday, November 19, 2026 3:16 PM
> > ...
Sorry for my late reply!
> > +static struct hv_pcibus_device *hv_pci_dev_to_hbus(struct pci_dev *pdev)
>
> nit: seems like this would be a good candidate for inlining.
Thanks, Hamza. The helper and its three callers are all in pci-hyperv.c,
so GCC can already inline it at -O2 without an explicit inline:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
I'd keep it static and let the compiler decide.
> > +{
> > + if (pdev->bus->ops != &hv_pcifront_ops)
>
> It's worth checking for !pci_is_root_bus(pdev->bus) here as well (since
> pci-hyperv only creates the root bus).
>
> Hamza
>
> > + return NULL;
> > +
> > + return container_of(pdev->bus->sysdata, struct hv_pcibus_device,
> > + sysdata);
> > +}
pci-hyperv exposes PCI functions directly on a root bus. It doesn't
expose any PCI-to-PCI bridges, so there's no child bus that could
inherit hv_pcifront_ops. A device behind an emulated PCIe host bridge
has different bus ops and is already rejected by the ops check, so IMO
here it's unnecessary to check !pci_is_root_bus(pdev->bus).
Thanks,
Dexuan