cxgbe: Don't leak memory resource if t4iov attach fails.

Co-authored by:	np
Reviewed by:	np
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D38580
This commit is contained in:
John Baldwin 2023-02-15 13:34:00 -08:00
parent 98844e99d4
commit d2070e5fa9

View File

@ -194,6 +194,7 @@ t4iov_attach(device_t dev)
{
struct t4iov_softc *sc;
uint32_t pl_rev, whoami;
int error;
sc = device_get_softc(dev);
sc->sc_dev = dev;
@ -217,10 +218,18 @@ t4iov_attach(device_t dev)
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);
}