diff options
author | jhb <jhb@FreeBSD.org> | 2004-01-22 16:07:03 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2004-01-22 16:07:03 +0000 |
commit | 9f489597075de2b2aaa8bf695f79c8e7b4e0a196 (patch) | |
tree | b58a6cc67f0875cc9e398410c637e93d2cf4beda | |
parent | 7a517ec35f80fe08da85e81fe1aa41bf8d798ab2 (diff) | |
download | FreeBSD-src-9f489597075de2b2aaa8bf695f79c8e7b4e0a196.zip FreeBSD-src-9f489597075de2b2aaa8bf695f79c8e7b4e0a196.tar.gz |
Fix the PCI attach routine to properly setup the IRQ and port resource
rid's and to deallocate resources if a failure occurs during attach. This
patch also fixes the driver to return failure if bus_alloc_resource() for
the IRQ fails rather than panic'ing on the next line by passing a NULL
resource to bus_setup_intr(). The other attachments already do all this.
Submitted by: Jun Su <csujun@263.net>
-rw-r--r-- | sys/dev/lnc/if_lnc_pci.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/sys/dev/lnc/if_lnc_pci.c b/sys/dev/lnc/if_lnc_pci.c index 3e876a6..72d0ab8 100644 --- a/sys/dev/lnc/if_lnc_pci.c +++ b/sys/dev/lnc/if_lnc_pci.c @@ -92,7 +92,6 @@ lnc_pci_attach(device_t dev) { lnc_softc_t *sc = device_get_softc(dev); unsigned command; - int rid = 0; int err = 0; bus_size_t lnc_mem_size; @@ -102,25 +101,31 @@ lnc_pci_attach(device_t dev) command |= PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN; pci_write_config(dev, PCIR_COMMAND, command, 4); - rid = PCIR_BAR(0); - sc->portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, + sc->portrid = PCIR_BAR(0); + sc->portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->portrid, 0, ~0, 1, RF_ACTIVE); - if (! sc->portres) + if (! sc->portres) { device_printf(dev, "Cannot allocate I/O ports\n"); - - rid = 0; - sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, + lnc_release_resources(dev); + return (ENXIO); + } + + sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irqrid, 0, ~0, 1, RF_ACTIVE|RF_SHAREABLE); - if (! sc->irqres) + if (! sc->irqres) { device_printf(dev, "Cannot allocate irq\n"); - + lnc_release_resources(dev); + return (ENXIO); + } err = bus_setup_intr(dev, sc->irqres, INTR_TYPE_NET, lncintr, sc, &sc->intrhand); - if (err) + if (err) { device_printf(dev, "Cannot setup irq handler\n"); - + lnc_release_resources(dev); + return (ENXIO); + } sc->lnc_btag = rman_get_bustag(sc->portres); sc->lnc_bhandle = rman_get_bushandle(sc->portres); @@ -161,7 +166,7 @@ lnc_pci_attach(device_t dev) if (err) { device_printf(dev, "Can't create DMA tag\n"); - /* XXX need to free currently allocated resources here */ + lnc_release_resources(dev); return (ENOMEM); } @@ -170,7 +175,7 @@ lnc_pci_attach(device_t dev) if (err) { device_printf(dev, "Couldn't allocate memory\n"); - /* XXX need to free currently allocated resources here */ + lnc_release_resources(dev); return (ENOMEM); } @@ -180,6 +185,8 @@ lnc_pci_attach(device_t dev) /* Call generic attach code */ if (! lnc_attach_common(dev)) { device_printf(dev, "Generic attach code failed\n"); + lnc_release_resources(dev); + return (ENXIO); } return (0); } |