diff --git a/sys/dev/cxgbe/t4_iov.c b/sys/dev/cxgbe/t4_iov.c --- a/sys/dev/cxgbe/t4_iov.c +++ b/sys/dev/cxgbe/t4_iov.c @@ -194,6 +194,7 @@ { struct t4iov_softc *sc; uint32_t pl_rev, whoami; + int error; sc = device_get_softc(dev); sc->sc_dev = dev; @@ -217,10 +218,18 @@ sc->sc_main = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev), pci_get_slot(dev), 4); - if (sc->sc_main == NULL) + if (sc->sc_main == NULL) { + bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid, + sc->regs_res); return (ENXIO); - if (T4_IS_MAIN_READY(sc->sc_main) == 0) - return (t4iov_attach_child(dev)); + } + if (T4_IS_MAIN_READY(sc->sc_main) == 0) { + error = t4iov_attach_child(dev); + if (error != 0) + bus_release_resource(dev, SYS_RES_MEMORY, sc->regs_rid, + sc->regs_res); + return (error); + } return (0); }