Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern In module_do_load(), consolidate checking for a pre...



details:   https://anonhg.NetBSD.org/src/rev/3bcdf4ff8e1f
branches:  trunk
changeset: 343491:3bcdf4ff8e1f
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Feb 06 22:48:07 2016 +0000

description:
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.)

diffstat:

 sys/kern/kern_module.c |  41 +++++++++++++----------------------------
 1 files changed, 13 insertions(+), 28 deletions(-)

diffs (79 lines):

diff -r a22df72d2f9f -r 3bcdf4ff8e1f sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Sat Feb 06 21:23:09 2016 +0000
+++ b/sys/kern/kern_module.c    Sat Feb 06 22:48:07 2016 +0000
@@ -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 @@
                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 @@
        }
 
        /*
-        * 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 @@
                        }
                        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);



Home | Main Index | Thread Index | Old Index