Module Name:    src
Committed By:   pgoyette
Date:           Sat Feb  6 22:48:07 UTC 2016

Modified Files:
        src/sys/kern: kern_module.c

Log Message:
In module_do_load(), consolidate checking for a pre-existing module,
and return a single error value EEXIST.  When making a recursive
call (to load required modules), treat a pre-existing module as
success.

Without this change, when a module was loaded by specific request
(as opposed to being loaded as a requirement of some other module),
we would always load the module from the file-system, and then
after making various sanity/compatability checks we would destroy
the new copy if there was a pre-existing copy.

Fixes PR kern/40764

XXX Note that if the module exists, we bypass all of the various
XXX "compatability" checks, including whether or not the existing
XXX module is of any particular class!  (In the previous code, we
XXX checked to see if the newly-loaded copy had the correct class,
XXX but not the pre-existing copy, which could have been loaded
XXX from a different path/filename.)


To generate a diff of this commit:
cvs rdiff -u -r1.109 -r1.110 src/sys/kern/kern_module.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_module.c
diff -u src/sys/kern/kern_module.c:1.109 src/sys/kern/kern_module.c:1.110
--- src/sys/kern/kern_module.c:1.109	Wed Dec  9 16:26:16 2015
+++ src/sys/kern/kern_module.c	Sat Feb  6 22:48:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_module.c,v 1.109 2015/12/09 16:26:16 maxv Exp $	*/
+/*	$NetBSD: kern_module.c,v 1.110 2016/02/06 22:48:07 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.109 2015/12/09 16:26:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.110 2016/02/06 22:48:07 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -936,21 +936,19 @@ module_do_load(const char *name, bool is
 		TAILQ_INSERT_TAIL(pending, mod, mod_chain);
 	} else {
 		/*
-		 * If a requisite module, check to see if it is
-		 * already present.
+		 * Check to see if module is already present.
 		 */
-		if (isdep) {
-			mod = module_lookup(name);
-			if (mod != NULL) {
-				if (modp != NULL) {
-					*modp = mod;
-				}
-				module_print("dependent module `%s' already "
-				    "loaded", name);
-				depth--;
-				return 0;
+		mod = module_lookup(name);
+		if (mod != NULL) {
+			if (modp != NULL) {
+				*modp = mod;
 			}
+			module_print("%s module `%s' already loaded",
+			    isdep ? "dependent" : "requested", name);
+			depth--;
+			return EEXIST;
 		}
+
 		mod = module_newmodule(MODULE_SOURCE_FILESYS);
 		if (mod == NULL) {
 			module_error("out of memory for `%s'", name);
@@ -1030,19 +1028,6 @@ module_do_load(const char *name, bool is
 	}
 
 	/*
-	 * Check to see if the module is already loaded.  If so, we may
-	 * have been recursively called to handle a dependency, so be sure
-	 * to set modp.
-	 */
-	if ((mod2 = module_lookup(mi->mi_name)) != NULL) {
-		if (modp != NULL)
-			*modp = mod2;
-		module_print("module `%s' already loaded", mi->mi_name);
-		error = EEXIST;
-		goto fail;
-	}
-
-	/*
 	 * Block circular dependencies.
 	 */
 	TAILQ_FOREACH(mod2, pending, mod_chain) {
@@ -1093,7 +1078,7 @@ module_do_load(const char *name, bool is
 			}
 			error = module_do_load(buf, true, flags, NULL,
 			    &mod2, MODULE_CLASS_ANY, true);
-			if (error != 0) {
+			if (error != 0 && error != EEXIST) {
 				module_error("recursive load failed for `%s' "
 				    "(`%s' required), error %d", mi->mi_name,
 				    buf, error);

Reply via email to