mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Add clone_setup() function rather than rely on lazy initialization.
Requested by: rwatson
This commit is contained in:
parent
03f0d9e8ae
commit
9397290e76
7 changed files with 19 additions and 9 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue