From 8da738fd11690df892eaedcf1fc18a9abca0d583 Mon Sep 17 00:00:00 2001 From: Alfred Perlstein Date: Thu, 5 Apr 2001 06:56:10 +0000 Subject: Don't leak resources: Don't leak iospace when irq allocation fails. (call wi_free()) Call bus_release_resource() with the correct "rid" obtained from bus_alloc_resource() that's saved in the softc instead of a hardcoded 0. --- sys/dev/wi/if_wi.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/dev/wi/if_wi.c b/sys/dev/wi/if_wi.c index 50beb56072be..bfe895ac3f9a 100644 --- a/sys/dev/wi/if_wi.c +++ b/sys/dev/wi/if_wi.c @@ -1685,6 +1685,7 @@ wi_alloc(dev, io_rid) sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid, 0, ~0, 1, RF_ACTIVE); if (!sc->irq) { + wi_free(dev); device_printf(dev, "No irq?!\n"); return (ENXIO); } @@ -1703,12 +1704,18 @@ static void wi_free(dev) { struct wi_softc *sc = device_get_softc(dev); - if (sc->iobase != NULL) - bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->iobase); - if (sc->irq != NULL) - bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq); - if (sc->mem != NULL) + if (sc->iobase != NULL) { + bus_release_resource(dev, SYS_RES_IOPORT, sc->iobase_rid, sc->iobase); + sc->iobase = NULL; + } + if (sc->irq != NULL) { + bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq); + sc->irq = NULL; + } + if (sc->mem != NULL) { bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem); + sc->mem = NULL; + } return; } -- cgit v1.3