prevent the lookup function from autoloading recursively. trunk
authorchristos <christos@NetBSD.org>
Mon, 11 Mar 2013 01:56:37 +0000
branchtrunk
changeset 217206 f98ea364779d
parent 217205 6b8cc8ea5957
child 217207 e629930e1fb9
prevent the lookup function from autoloading recursively.
sys/net/npf/npf_rproc.c
--- a/sys/net/npf/npf_rproc.c	Mon Mar 11 01:43:50 2013 +0000
+++ b/sys/net/npf/npf_rproc.c	Mon Mar 11 01:56:37 2013 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_rproc.c,v 1.8 2013/03/11 01:43:50 christos Exp $	*/
+/*	$NetBSD: npf_rproc.c,v 1.9 2013/03/11 01:56:37 christos Exp $	*/
 
 /*-
  * Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -102,11 +102,11 @@
 #define NPF_EXT_PREFLEN (sizeof(npf_ext_prefix) - 1)
 
 static npf_ext_t *
-npf_ext_lookup(const char *name)
+npf_ext_lookup(const char *name, bool autoload)
 {
 	npf_ext_t *ext;
 	char modname[RPROC_NAME_LEN + NPF_EXT_PREFLEN];
-	int error, loaded = 0;
+	int error;
 
 	KASSERT(mutex_owned(&ext_lock));
 
@@ -115,11 +115,11 @@
 		if (strcmp(ext->ext_callname, name) == 0)
 			break;
 
-	if (ext != NULL || loaded != 0)
+	if (ext != NULL || !autoload)
 		return ext;
 
 	mutex_exit(&ext_lock);
-	loaded++;
+	autoload = false;
 	snprintf(modname, sizeof(modname), "%s%s", npf_ext_prefix, name);
 	error = module_autoload(modname, MODULE_CLASS_MISC);
 	mutex_enter(&ext_lock);
@@ -139,7 +139,7 @@
 	ext->ext_ops = ops;
 
 	mutex_enter(&ext_lock);
-	if (npf_ext_lookup(name)) {
+	if (npf_ext_lookup(name, false)) {
 		mutex_exit(&ext_lock);
 		kmem_free(ext, sizeof(npf_ext_t));
 		return NULL;
@@ -167,7 +167,7 @@
 		mutex_exit(&ext_lock);
 		return EBUSY;
 	}
-	KASSERT(npf_ext_lookup(ext->ext_callname));
+	KASSERT(npf_ext_lookup(ext->ext_callname, false));
 	LIST_REMOVE(ext, ext_entry);
 	mutex_exit(&ext_lock);
 
@@ -188,7 +188,7 @@
 	}
 
 	mutex_enter(&ext_lock);
-	ext = npf_ext_lookup(name);
+	ext = npf_ext_lookup(name, true);
 	if (ext) {
 		atomic_inc_uint(&ext->ext_refcnt);
 	}