diff options
author | brian <brian@FreeBSD.org> | 2000-06-09 17:03:29 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2000-06-09 17:03:29 +0000 |
commit | 1c8d742b1390d8c600bf507beb7e0bd9d41043d5 (patch) | |
tree | fd18ef941252ab107b75439b3ce2d2fcecedf693 /sys/dev/lnc | |
parent | 1226423ba74bbb12b78fdec0a86fb64d638ae045 (diff) | |
download | FreeBSD-src-1c8d742b1390d8c600bf507beb7e0bd9d41043d5.zip FreeBSD-src-1c8d742b1390d8c600bf507beb7e0bd9d41043d5.tar.gz |
Dynamically allocate softc structures
Reviewed by: Mark Knight <mkn@uk.FreeBSD.org>
Diffstat (limited to 'sys/dev/lnc')
-rw-r--r-- | sys/dev/lnc/if_lnc.c | 2 | ||||
-rw-r--r-- | sys/dev/lnc/if_lnc_isa.c | 38 |
2 files changed, 33 insertions, 7 deletions
diff --git a/sys/dev/lnc/if_lnc.c b/sys/dev/lnc/if_lnc.c index 2144891..18f829c 100644 --- a/sys/dev/lnc/if_lnc.c +++ b/sys/dev/lnc/if_lnc.c @@ -96,8 +96,6 @@ #error "The lnc device requires the old isa compatibility shims" #endif -lnc_softc_t lnc_softc[NLNC]; - static char const * const nic_ident[] = { "Unknown", "BICC", diff --git a/sys/dev/lnc/if_lnc_isa.c b/sys/dev/lnc/if_lnc_isa.c index 9cb8406..2301bd4 100644 --- a/sys/dev/lnc/if_lnc_isa.c +++ b/sys/dev/lnc/if_lnc_isa.c @@ -31,6 +31,7 @@ */ #include <sys/param.h> +#include <sys/malloc.h> #include <sys/systm.h> #include <sys/socket.h> @@ -60,10 +61,38 @@ int lnc_attach __P((struct isa_device *)); static int dec_macaddr_extract __P((u_char[], lnc_softc_t *)); static ointhand2_t lncintr; -extern lnc_softc_t lnc_softc[]; extern int lnc_attach_sc __P((lnc_softc_t *, int)); extern void lncintr_sc __P((lnc_softc_t *)); +static lnc_softc_t * +lnc_getsoftc(int unit) +{ + static lnc_softc_t **sc; + static int units; + + if (unit >= units) { + /* Reallocate more softc pointers */ + + lnc_softc_t **nsc; + int n; + + n = unit + 1; + nsc = malloc(sizeof(lnc_softc_t *) * n, M_DEVBUF, M_WAITOK); + if (units) + bcopy(sc, nsc, sizeof(lnc_softc_t *) * units); + bzero(nsc + units, sizeof(lnc_softc_t *) * (n - units)); + if (sc) + free(sc, M_DEVBUF); + units = n; + sc = nsc; + } + + if (sc[unit] == NULL) + sc[unit] = malloc(sizeof(lnc_softc_t), M_DEVBUF, M_WAITOK); + + return sc[unit]; +} + int ne2100_probe(lnc_softc_t *sc, unsigned iobase) { @@ -250,7 +279,7 @@ lnc_probe(struct isa_device * isa_dev) { int nports; int unit = isa_dev->id_unit; - lnc_softc_t *sc = &lnc_softc[unit]; + lnc_softc_t *sc = lnc_getsoftc(unit); unsigned iobase = isa_dev->id_iobase; #ifdef DIAGNOSTIC @@ -275,7 +304,7 @@ int lnc_attach(struct isa_device * isa_dev) { int unit = isa_dev->id_unit; - lnc_softc_t *sc = &lnc_softc[unit]; + lnc_softc_t *sc = lnc_getsoftc(unit); int result; isa_dev->id_ointr = lncintr; @@ -299,6 +328,5 @@ lnc_attach(struct isa_device * isa_dev) static void lncintr(int unit) { - lnc_softc_t *sc = &lnc_softc[unit]; - lncintr_sc (sc); + lncintr_sc(lnc_getsoftc(unit)); } |