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>
This commit is contained in:
John Baldwin 2004-01-22 16:07:03 +00:00
parent dec04f43d9
commit acf7d97237
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=124838

View file

@ -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");
lnc_release_resources(dev);
return (ENXIO);
}
rid = 0;
sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
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);
}