diff options
author | Brian Somers <brian@FreeBSD.org> | 2000-06-09 17:03:29 +0000 |
---|---|---|
committer | Brian Somers <brian@FreeBSD.org> | 2000-06-09 17:03:29 +0000 |
commit | fa33ce4b09fa1ff76cc86d5b1e059e5ba03e1c57 (patch) | |
tree | 242bf018c79c1db3fb7bb5236b421da8eca4d545 /sys/dev/lnc | |
parent | 7bf9834a55bcfb1d732ffcd17a3ab8ab0b5e8df3 (diff) | |
download | src-fa33ce4b09fa1ff76cc86d5b1e059e5ba03e1c57.tar.gz src-fa33ce4b09fa1ff76cc86d5b1e059e5ba03e1c57.zip |
Dynamically allocate softc structures
Reviewed by: Mark Knight <mkn@uk.FreeBSD.org>
Notes
Notes:
svn path=/head/; revision=61457
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 2144891289b8..18f829c007d6 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 9cb84062cb5a..2301bd447529 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)); } |