Index: sys/kern/kern_module.c =================================================================== --- sys/kern/kern_module.c (revision 295464) +++ sys/kern/kern_module.c (working copy) @@ -214,16 +214,24 @@ module_lookupbyname(const char *name) { module_t mod; + int xlocked; int err; - MOD_LOCK_ASSERT; - + /* + * If the context is not properly locked, apply the proper + * locks here: + */ + xlocked = sx_xlocked(&modules_sx); + if (!xlocked) + MOD_SLOCK; TAILQ_FOREACH(mod, &modules, link) { err = strcmp(mod->name, name); if (err == 0) - return (mod); + break; } - return (NULL); + if (!xlocked) + MOD_SUNLOCK; + return (mod); } module_t