Index: sys/dev/pci/pci.c =================================================================== --- sys/dev/pci/pci.c +++ sys/dev/pci/pci.c @@ -6261,11 +6261,9 @@ pci_find_pcie_root_port(device_t dev) { struct pci_devinfo *dinfo; - devclass_t pci_class; device_t pcib, bus; - pci_class = devclass_find("pci"); - KASSERT(device_get_devclass(device_get_parent(dev)) == pci_class, + KASSERT(devclass_is_derived_from("pci", dev), ("%s: non-pci device %s", __func__, device_get_nameunit(dev))); /* @@ -6285,7 +6283,7 @@ * pcib's parent must be a PCI bus for this to be a * PCI-PCI bridge. */ - if (device_get_devclass(device_get_parent(pcib)) != pci_class) + if (!devclass_is_derived_from("pci", device_get_parent(pcib))) return (NULL); dinfo = device_get_ivars(pcib); Index: sys/kern/subr_bus.c =================================================================== --- sys/kern/subr_bus.c +++ sys/kern/subr_bus.c @@ -1755,6 +1755,23 @@ return (0); } +bool +devclass_is_derived_from(const char *name, device_t dev) +{ + devclass_t dc, ddc; + + dc = devclass_find(name); + if (dc == NULL) + return (false); + ddc = device_get_devclass(dev); + while (dc != NULL) { + if (dc == ddc) + return (true); + dc = dc->parent; + } + return (false); +} + /** * @internal * @brief Make a new device and add it as a child of @p parent Index: sys/sys/bus.h =================================================================== --- sys/sys/bus.h +++ sys/sys/bus.h @@ -652,6 +652,7 @@ devclass_t devclass_get_parent(devclass_t dc); struct sysctl_ctx_list *devclass_get_sysctl_ctx(devclass_t dc); struct sysctl_oid *devclass_get_sysctl_tree(devclass_t dc); +bool devclass_is_derived_from(const char *, device_t); /* * Access functions for device resources.