From 544a9b9ee34a52ae23281875d86d7412a9a1ff29 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 11 Mar 2004 12:58:55 +0000 Subject: [PATCH] Add clone_setup() function rather than rely on lazy initialization. Requested by: rwatson --- sys/dev/nmdm/nmdm.c | 1 + sys/dev/snp/snp.c | 1 + sys/kern/kern_conf.c | 22 +++++++++++++--------- sys/net/if_tap.c | 1 + sys/net/if_tun.c | 1 + sys/sys/conf.h | 1 + sys/sys/linedisc.h | 1 + 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sys/dev/nmdm/nmdm.c b/sys/dev/nmdm/nmdm.c index 22b9b51fb768..841495f84fd9 100644 --- a/sys/dev/nmdm/nmdm.c +++ b/sys/dev/nmdm/nmdm.c @@ -594,6 +594,7 @@ nmdm_modevent(module_t mod, int type, void *data) switch(type) { case MOD_LOAD: + clone_setup(&nmdmclones); tag = EVENTHANDLER_REGISTER(dev_clone, nmdm_clone, 0, 1000); if (tag == NULL) return (ENOMEM); diff --git a/sys/dev/snp/snp.c b/sys/dev/snp/snp.c index 19dc1e7d6f80..ebf888e44481 100644 --- a/sys/dev/snp/snp.c +++ b/sys/dev/snp/snp.c @@ -631,6 +631,7 @@ snp_modevent(mod, type, data) switch (type) { case MOD_LOAD: /* XXX error checking. */ + clone_setup(&snpclones); eh_tag = EVENTHANDLER_REGISTER(dev_clone, snp_clone, 0, 1000); snooplinedisc = ldisc_register(LDISC_LOAD, &snpdisc); break; diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 8f8d1a45c9ef..6ca948db7e01 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -693,6 +693,14 @@ struct clonedevs { LIST_HEAD(,cdev) head; }; +void +clone_setup(struct clonedevs **cdp) +{ + + *cdp = malloc(sizeof **cdp, M_DEVBUF, M_WAITOK | M_ZERO); + LIST_INIT(&(*cdp)->head); +} + int clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, dev_t *dp, u_int extra) { @@ -700,20 +708,15 @@ clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, dev_t *dp, u_i dev_t dev, dl, de; int unit, low, u; + KASSERT(*cdp != NULL, + ("clone_setup() not called in driver \"%s\"", csw->d_name)); KASSERT(!(extra & CLONE_UNITMASK), - ("Illegal extra bits (0x%x) in clone_create", extra)); + ("Illegal extra bits (0x%x) in clone_create", extra)); KASSERT(*up <= CLONE_UNITMASK, - ("Too high unit (0x%x) in clone_create", *up)); + ("Too high unit (0x%x) in clone_create", *up)); if (csw->d_maj == MAJOR_AUTO) find_major(csw); - /* if clonedevs have not been initialized, we do it here */ - cd = *cdp; - if (cd == NULL) { - cd = malloc(sizeof *cd, M_DEVBUF, M_WAITOK | M_ZERO); - LIST_INIT(&cd->head); - *cdp = cd; - } /* * Search the list for a lot of things in one go: @@ -726,6 +729,7 @@ clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, dev_t *dp, u_i unit = *up; low = 0; de = dl = NULL; + cd = *cdp; LIST_FOREACH(dev, &cd->head, si_clone) { u = dev2unit(dev); if (u == (unit | extra)) { diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index 8b40b45271b4..59258c7170ba 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -140,6 +140,7 @@ tapmodevent(mod, type, data) SLIST_INIT(&taphead); + clone_setup(&tapclones); eh_tag = EVENTHANDLER_REGISTER(dev_clone, tapclone, 0, 1000); if (eh_tag == NULL) return (ENOMEM); diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 222ce42731a2..3bedf1c130a9 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -150,6 +150,7 @@ tunmodevent(module_t mod, int type, void *data) switch (type) { case MOD_LOAD: + clone_setup(&tunclones); tag = EVENTHANDLER_REGISTER(dev_clone, tunclone, 0, 1000); if (tag == NULL) return (ENOMEM); diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 40ee4c346d5c..f699882cc96f 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -297,6 +297,7 @@ static moduledata_t name##_mod = { \ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) +void clone_setup(struct clonedevs **cdp); void clone_cleanup(struct clonedevs **); #define CLONE_UNITMASK 0xfffff #define CLONE_FLAG0 (CLONE_UNITMASK + 1) diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h index 40ee4c346d5c..f699882cc96f 100644 --- a/sys/sys/linedisc.h +++ b/sys/sys/linedisc.h @@ -297,6 +297,7 @@ static moduledata_t name##_mod = { \ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) +void clone_setup(struct clonedevs **cdp); void clone_cleanup(struct clonedevs **); #define CLONE_UNITMASK 0xfffff #define CLONE_FLAG0 (CLONE_UNITMASK + 1)