From d16875a8066893408066a3d1a3ed59e41f3a1dee Mon Sep 17 00:00:00 2001 From: "Landon J. Fuller" Date: Sat, 2 Dec 2017 01:07:41 +0000 Subject: [PATCH] bhndb(4): Fix leak of child devices and MSI vectors. - Add missing call to device_delete_children() in bhndb_detach(), without which we're left with stale child devices on module unload. - Pass the parent PCI device to pci_release_msi(), not the bhndb_pci(4) child. Approved by: adrian (mentor, implicit) Sponsored by: The FreeBSD Foundation --- sys/dev/bhnd/bhndb/bhndb.c | 4 ++++ sys/dev/bhnd/bhndb/bhndb_pci.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/dev/bhnd/bhndb/bhndb.c b/sys/dev/bhnd/bhndb/bhndb.c index d2f454ec2906..bbf819131b81 100644 --- a/sys/dev/bhnd/bhndb/bhndb.c +++ b/sys/dev/bhnd/bhndb/bhndb.c @@ -639,6 +639,10 @@ bhndb_generic_detach(device_t dev) if ((error = bus_generic_detach(dev))) return (error); + /* Delete children */ + if ((error = device_delete_children(dev))) + return (error); + /* Clean up our service registry */ if ((error = bhnd_service_registry_fini(&sc->services))) return (error); diff --git a/sys/dev/bhnd/bhndb/bhndb_pci.c b/sys/dev/bhnd/bhndb/bhndb_pci.c index 8ccf77f9e63b..d381f8a01524 100644 --- a/sys/dev/bhnd/bhndb/bhndb_pci.c +++ b/sys/dev/bhnd/bhndb/bhndb_pci.c @@ -303,8 +303,10 @@ bhndb_pci_alloc_msi(struct bhndb_pci_softc *sc, int *msi_count) return (error); } - if (count < BHNDB_PCI_MSI_COUNT) + if (count < BHNDB_PCI_MSI_COUNT) { + pci_release_msi(sc->parent); return (ENXIO); + } *msi_count = count; return (0); @@ -412,7 +414,7 @@ bhndb_pci_attach(device_t dev) bhndb_free_intr_isrc(sc->isrc); if (sc->msi_count > 0) - pci_release_msi(dev); + pci_release_msi(sc->parent); if (cores != NULL) free(cores, M_BHND); @@ -449,7 +451,7 @@ bhndb_pci_detach(device_t dev) /* Release MSI interrupts */ if (sc->msi_count > 0) - pci_release_msi(dev); + pci_release_msi(sc->parent); /* Disable PCI bus mastering */ pci_disable_busmaster(sc->parent);