From 916076fefc3503056463e4550a9e939096dd6945 Mon Sep 17 00:00:00 2001 From: Thomas Moestl Date: Mon, 18 Jun 2001 18:36:34 +0000 Subject: [PATCH] Call bus_teardown_intr when csa_attach fails after the interrupt has been set up. PR: kern/28178 Reviewed by: cg MFC after: 2 weeks --- sys/dev/sound/pci/csa.c | 60 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/sys/dev/sound/pci/csa.c b/sys/dev/sound/pci/csa.c index b916cdc29408..30957c395750 100644 --- a/sys/dev/sound/pci/csa.c +++ b/sys/dev/sound/pci/csa.c @@ -241,6 +241,7 @@ csa_attach(device_t dev) sc_p scp; csa_res *resp; struct sndcard_func *func; + int error = ENXIO; scp = device_get_softc(dev); @@ -266,55 +267,40 @@ csa_attach(device_t dev) return (ENXIO); resp->mem_rid = PCIR_MAPS + 4; resp->mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &resp->mem_rid, 0, ~0, 1, RF_ACTIVE); - if (resp->mem == NULL) { - bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); - return (ENXIO); - } + if (resp->mem == NULL) + goto err_io; resp->irq_rid = 0; resp->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &resp->irq_rid, 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE); - if (resp->irq == NULL) { - bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); - bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); - return (ENXIO); - } + if (resp->irq == NULL) + goto err_mem; /* Enable interrupt. */ - if (snd_setup_intr(dev, resp->irq, INTR_MPSAFE, csa_intr, scp, &scp->ih)) { - bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); - bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); - bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq); - return (ENXIO); - } + if (snd_setup_intr(dev, resp->irq, INTR_MPSAFE, csa_intr, scp, &scp->ih)) + goto err_intr; #if 0 if ((csa_readio(resp, BA0_HISR) & HISR_INTENA) == 0) csa_writeio(resp, BA0_HICR, HICR_IEV | HICR_CHGM); #endif /* Initialize the chip. */ - if (csa_initialize(scp)) { - bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); - bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); - bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq); - return (ENXIO); - } + if (csa_initialize(scp)) + goto err_teardown; /* Reset the Processor. */ csa_resetdsp(resp); /* Download the Processor Image to the processor. */ - if (csa_downloadimage(resp)) { - bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); - bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); - bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq); - return (ENXIO); - } + if (csa_downloadimage(resp)) + goto err_teardown; /* Attach the children. */ /* PCM Audio */ func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT); - if (func == NULL) - return (ENOMEM); + if (func == NULL) { + error = ENOMEM; + goto err_teardown; + } bzero(func, sizeof(*func)); func->varinfo = &scp->binfo; func->func = SCF_PCM; @@ -323,8 +309,10 @@ csa_attach(device_t dev) /* Midi Interface */ func = malloc(sizeof(struct sndcard_func), M_DEVBUF, M_NOWAIT); - if (func == NULL) - return (ENOMEM); + if (func == NULL) { + error = ENOMEM; + goto err_teardown; + } bzero(func, sizeof(*func)); func->varinfo = &scp->binfo; func->func = SCF_MIDI; @@ -334,6 +322,16 @@ csa_attach(device_t dev) bus_generic_attach(dev); return (0); + +err_teardown: + bus_teardown_intr(dev, resp->irq, scp->ih); +err_intr: + bus_release_resource(dev, SYS_RES_IRQ, resp->irq_rid, resp->irq); +err_mem: + bus_release_resource(dev, SYS_RES_MEMORY, resp->mem_rid, resp->mem); +err_io: + bus_release_resource(dev, SYS_RES_MEMORY, resp->io_rid, resp->io); + return (error); } static int