summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_device.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-02-14 13:47:06 +0000
committerglebius <glebius@FreeBSD.org>2005-02-14 13:47:06 +0000
commit8c12be1b6054637d08d9bf43c6a77866c5b641b2 (patch)
treeea2f0b4cc239bccdfa193513488f97cc28846ff4 /sys/netgraph/ng_device.c
parent63ac35c802473bafbc0508895d6234bf6ec06358 (diff)
downloadFreeBSD-src-8c12be1b6054637d08d9bf43c6a77866c5b641b2.zip
FreeBSD-src-8c12be1b6054637d08d9bf43c6a77866c5b641b2.tar.gz
Make WITNESS happier:
- refactor ngd_constructor, so that make_dev() is called without any locks held, since it mallocs memory with M_WAITOK flag. - rename global mtx, to have name different to per-node mtx MFC after: 2 weeks
Diffstat (limited to 'sys/netgraph/ng_device.c')
-rw-r--r--sys/netgraph/ng_device.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/sys/netgraph/ng_device.c b/sys/netgraph/ng_device.c
index 09b5492..6230ccf 100644
--- a/sys/netgraph/ng_device.c
+++ b/sys/netgraph/ng_device.c
@@ -150,44 +150,38 @@ ng_device_constructor(node_p node)
if (priv == NULL)
return (ENOMEM);
- mtx_init(&priv->ngd_mtx, "ng_device", NULL, MTX_DEF);
- mtx_lock(&priv->ngd_mtx);
-
mtx_lock(&ng_device_mtx);
-
priv->unit = get_free_unit();
if(priv->unit < 0) {
printf("%s: No free unit found by get_free_unit(), "
"increase MAX_NGD\n",__func__);
mtx_unlock(&ng_device_mtx);
- mtx_destroy(&priv->ngd_mtx);
- FREE(priv, M_NETGRAPH);
- return(EINVAL);
- }
-
- priv->ngddev = make_dev(&ngd_cdevsw, unit2minor(priv->unit), UID_ROOT,
- GID_WHEEL, 0600, NG_DEVICE_DEVNAME "%d", priv->unit);
- if(priv->ngddev == NULL) {
- printf("%s(): make_dev() failed\n",__func__);
- mtx_unlock(&ng_device_mtx);
- mtx_destroy(&priv->ngd_mtx);
FREE(priv, M_NETGRAPH);
return(EINVAL);
}
-
SLIST_INSERT_HEAD(&ngd_nodes, priv, links);
-
mtx_unlock(&ng_device_mtx);
+ /* Initialize mutexes and queue */
+ mtx_init(&priv->ngd_mtx, "ng_device", NULL, MTX_DEF);
mtx_init(&priv->readq.ifq_mtx, "ng_device queue", NULL, MTX_DEF);
IFQ_SET_MAXLEN(&priv->readq, ifqmaxlen);
/* Link everything together */
NG_NODE_SET_PRIVATE(node, priv);
priv->node = node;
+
+ priv->ngddev = make_dev(&ngd_cdevsw, unit2minor(priv->unit), UID_ROOT,
+ GID_WHEEL, 0600, NG_DEVICE_DEVNAME "%d", priv->unit);
+ if(priv->ngddev == NULL) {
+ printf("%s(): make_dev() failed\n",__func__);
+ mtx_destroy(&priv->ngd_mtx);
+ mtx_destroy(&priv->readq.ifq_mtx);
+ FREE(priv, M_NETGRAPH);
+ return(EINVAL);
+ }
+ /* XXX: race here? */
priv->ngddev->si_drv1 = priv;
-
- mtx_unlock(&priv->ngd_mtx);
return(0);
}
@@ -547,7 +541,7 @@ ng_device_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
- mtx_init(&ng_device_mtx, "ng_device", NULL, MTX_DEF);
+ mtx_init(&ng_device_mtx, "ng_device global", NULL, MTX_DEF);
break;
case MOD_UNLOAD:
mtx_destroy(&ng_device_mtx);
OpenPOWER on IntegriCloud