Module Name: src Committed By: pgoyette Date: Thu Dec 14 22:29:00 UTC 2017
Modified Files: src/sys/kern: kern_module.c Log Message: 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(). To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 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.129 src/sys/kern/kern_module.c:1.130 --- src/sys/kern/kern_module.c:1.129 Thu Dec 14 11:45:40 2017 +++ src/sys/kern/kern_module.c Thu Dec 14 22:28:59 2017 @@ -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 @@ module_do_load(const char *name, bool is */ 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 @@ module_do_load(const char *name, bool is } /* + * 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_do_load(const char *name, bool is 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: