Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Remove the check for duplicate-module-name-on-pendi...



details:   https://anonhg.NetBSD.org/src/rev/1b4d1f6d92ab
branches:  trunk
changeset: 828458:1b4d1f6d92ab
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Thu Dec 14 22:28:59 2017 +0000

description:
Remove the check for duplicate-module-name-on-pending-list since it really
doesn't help.  The check really cannot fail, and it only looks at the list
belonging to the current level of recursion.

Instead, verify that the module's modcmd(MODULE_CMD_INIT, ...) does not
introduce a duplicate module name as a result of recursively calling
module_do_load().

diffstat:

 sys/kern/kern_module.c |  31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)

diffs (66 lines):

diff -r f3b610de4076 -r 1b4d1f6d92ab sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Thu Dec 14 22:06:54 2017 +0000
+++ b/sys/kern/kern_module.c    Thu Dec 14 22:28:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_module.c,v 1.129 2017/12/14 11:45:40 pgoyette Exp $       */
+/*     $NetBSD: kern_module.c,v 1.130 2017/12/14 22:28:59 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.129 2017/12/14 11:45:40 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.130 2017/12/14 22:28:59 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -1047,18 +1047,7 @@
         */
        if (mod->mod_source == MODULE_SOURCE_FILESYS) {
                mod2 = module_lookup(mod->mod_info->mi_name);
-               if (mod2 == NULL) {
-                       TAILQ_FOREACH(mod2, pending, mod_chain) {
-                               if (strcmp(mod2->mod_info->mi_name, name) == 0) {
-                                       break;
-                               }
-                       }
-               }
-
-               if (mod2 == NULL) {
-                       module_error("newly added module `%s'"
-                           " not found", mod->mod_info->mi_name);
-               } else if (mod2 != mod) {
+               if ( mod2 && mod2 != mod) {
                        module_error("module with name `%s' already loaded",
                            mod2->mod_info->mi_name);
                        error = EEXIST;
@@ -1161,6 +1150,18 @@
        }
 
        /*
+        * If a recursive load already added a module with the same
+        * name, abort.
+        */
+       mod2 = module_lookup(mi->mi_name);
+       if (mod2 && mod2 != mod) {
+               module_error("recursive load causes duplicate module `%s'",
+                   mi->mi_name);
+               error = EEXIST;
+               goto fail1;
+       }
+
+       /*
         * Good, the module loaded successfully.  Put it onto the
         * list and add references to its requisite modules.
         */
@@ -1182,6 +1183,8 @@
        module_print("module `%s' loaded successfully", mi->mi_name);
        return 0;
 
+ fail1:
+       (*mi->mi_modcmd)(MODULE_CMD_FINI, NULL);
  fail:
        kobj_unload(mod->mod_kobj);
  fail2:



Home | Main Index | Thread Index | Old Index