From 902f6373cdc56e17511879e7daae67a0a31aaada Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 28 Jul 2005 16:33:25 +0000 Subject: [PATCH] Remove unnecessary initialisations. Return ENXIO instead of 1 in an_pccard_probe. Separate error path and normal normal return in ac_pccard_attach. GC AN_PCI_PLX_LOIO. Don't mess with PCI controll register, it's already down by the PCI layer. Submitted-by: Sepherosa Ziehau In addition, reverse the return value of an_probe. It doesn't make sense to return 0 on failure, if the callee are interested only in the error, not the success code. --- sys/dev/netif/an/if_an.c | 16 ++++++++-------- sys/dev/netif/an/if_an_isa.c | 12 ++++++------ sys/dev/netif/an/if_an_pccard.c | 18 ++++++++---------- sys/dev/netif/an/if_an_pci.c | 19 ++----------------- 4 files changed, 24 insertions(+), 41 deletions(-) diff --git a/sys/dev/netif/an/if_an.c b/sys/dev/netif/an/if_an.c index d58bcabe73..1625f52180 100644 --- a/sys/dev/netif/an/if_an.c +++ b/sys/dev/netif/an/if_an.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an.c,v 1.2.2.13 2003/02/11 03:32:48 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an.c,v 1.27 2005/07/27 21:56:32 joerg Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an.c,v 1.28 2005/07/28 16:33:25 joerg Exp $ */ /* @@ -320,12 +320,12 @@ an_probe(dev) bzero((char *)&ssid, sizeof(ssid)); error = an_alloc_port(dev, 0, AN_IOSIZ); - if (error != 0) - return (0); + if (error) + return (error); /* can't do autoprobing */ if (rman_get_start(sc->port_res) == -1) - return(0); + return(ENXIO); /* * We need to fake up a softc structure long enough @@ -348,16 +348,16 @@ an_probe(dev) /* No need for an_init_mpi350_desc since it will be done in attach */ if (an_cmd(sc, AN_CMD_READCFG, 0)) - return(0); + return(ENXIO); if (an_read_record(sc, (struct an_ltv_gen *)&ssid)) - return(0); + return(ENXIO); /* See if the ssid matches what we expect ... but doesn't have to */ if (strcmp(ssid.an_ssid1, AN_DEF_SSID)) - return(0); + return(ENXIO); - return(AN_IOSIZ); + return(0); } /* diff --git a/sys/dev/netif/an/if_an_isa.c b/sys/dev/netif/an/if_an_isa.c index e8b9d70155..5fda3a6f24 100644 --- a/sys/dev/netif/an/if_an_isa.c +++ b/sys/dev/netif/an/if_an_isa.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an_isa.c,v 1.1.2.5 2003/02/01 03:25:12 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an_isa.c,v 1.11 2005/07/27 21:56:32 joerg Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an_isa.c,v 1.12 2005/07/28 16:33:25 joerg Exp $ */ /* @@ -84,21 +84,21 @@ static int an_probe_isa(dev) device_t dev; { - int error = 0; + int error; error = ISA_PNP_PROBE(device_get_parent(dev), dev, an_ids); if (error == ENXIO) return(error); error = an_probe(dev); - an_release_resources(dev); - if (error == 0) - return (ENXIO); + if (error) + goto back; error = an_alloc_irq(dev, 0, 0); - an_release_resources(dev); if (!error) device_set_desc(dev, "Aironet ISA4500/ISA4800"); +back: + an_release_resources(dev); return (error); } diff --git a/sys/dev/netif/an/if_an_pccard.c b/sys/dev/netif/an/if_an_pccard.c index f3f97a137d..f8a6b8be4e 100644 --- a/sys/dev/netif/an/if_an_pccard.c +++ b/sys/dev/netif/an/if_an_pccard.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an_pccard.c,v 1.1.2.6 2003/02/01 03:25:12 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an_pccard.c,v 1.11 2005/07/27 21:56:32 joerg Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an_pccard.c,v 1.12 2005/07/28 16:33:25 joerg Exp $ */ /* @@ -131,12 +131,11 @@ an_pccard_probe(device_t dev) { int error; - error = an_probe(dev); /* 0 is failure for now */ - if (error != 0) { + error = an_probe(dev); + if (error == 0) { device_set_desc(dev, "Aironet PC4500/PC4800"); error = an_alloc_irq(dev, 0, 0); - } else - error = 1; + } an_release_resources(dev); return (error); } @@ -156,10 +155,9 @@ an_pccard_attach(device_t dev) sc->an_btag = rman_get_bustag(sc->port_res); error = an_attach(sc, dev, flags); - if (error) { + if (error) goto fail; - } - + /* * Must setup the interrupt after the an_attach to prevent racing. */ @@ -170,9 +168,9 @@ an_pccard_attach(device_t dev) ifmedia_removeall(&sc->an_ifmedia); goto fail; } + return 0; fail: - if (error) - an_release_resources(dev); + an_release_resources(dev); return (error); } diff --git a/sys/dev/netif/an/if_an_pci.c b/sys/dev/netif/an/if_an_pci.c index ead77d7d9f..b9824b6408 100644 --- a/sys/dev/netif/an/if_an_pci.c +++ b/sys/dev/netif/an/if_an_pci.c @@ -30,7 +30,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/an/if_an_pci.c,v 1.2.2.8 2003/02/11 03:32:48 ambrisko Exp $ - * $DragonFly: src/sys/dev/netif/an/if_an_pci.c,v 1.14 2005/07/28 16:22:59 joerg Exp $ + * $DragonFly: src/sys/dev/netif/an/if_an_pci.c,v 1.15 2005/07/28 16:33:25 joerg Exp $ */ /* @@ -92,7 +92,6 @@ struct an_type { const char *an_name; }; -#define AN_PCI_PLX_LOIO 0x14 /* PLX chip iobase */ #define AN_PCI_LOIO 0x18 /* Aironet iobase */ static const struct an_type an_devs[] = { @@ -135,9 +134,8 @@ static int an_attach_pci(dev) device_t dev; { - u_int32_t command; struct an_softc *sc; - int flags, error = 0; + int flags, error; sc = device_get_softc(dev); flags = device_get_flags(dev); @@ -147,19 +145,6 @@ an_attach_pci(dev) sc->mpi350 = 1; sc->port_rid = PCIR_MAPS; } else { - /* - * Map control/status registers. - */ - command = pci_read_config(dev, PCIR_COMMAND, 4); - command |= PCIM_CMD_PORTEN; - pci_write_config(dev, PCIR_COMMAND, command, 4); - command = pci_read_config(dev, PCIR_COMMAND, 4); - - if (!(command & PCIM_CMD_PORTEN)) { - device_printf(dev, "failed to enable I/O ports!\n"); - error = ENXIO; - goto fail; - } sc->port_rid = AN_PCI_LOIO; } error = an_alloc_port(dev, sc->port_rid, 1); -- 2.41.0