Module Name: src Committed By: pgoyette Date: Wed Jun 19 15:01:01 UTC 2019
Modified Files: src/sys/kern: kern_module.c Log Message: In case of error resolving symbol references, we cannot rely on the module's name still being available - it may be destroyed when kobj_affix() unloads the object. So make a copy of the name first so we can use it in a useful error message. (Without this, I've have affix errors go into an infinite loop trying to print the error message!) To generate a diff of this commit: cvs rdiff -u -r1.135 -r1.136 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.135 src/sys/kern/kern_module.c:1.136 --- src/sys/kern/kern_module.c:1.135 Tue Jun 11 15:20:57 2019 +++ src/sys/kern/kern_module.c Wed Jun 19 15:01:01 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_module.c,v 1.135 2019/06/11 15:20:57 pgoyette Exp $ */ +/* $NetBSD: kern_module.c,v 1.136 2019/06/19 15:01:01 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.135 2019/06/11 15:20:57 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.136 2019/06/19 15:01:01 pgoyette Exp $"); #define _MODULE_INTERNAL @@ -1214,12 +1214,21 @@ module_do_load(const char *name, bool is * We loaded all needed modules successfully: perform global * relocations and initialize. */ - error = kobj_affix(mod->mod_kobj, mi->mi_name); - if (error != 0) { - /* Cannot touch 'mi' as the module is now gone. */ - module_error("unable to affix module `%s', error %d", name, - error); - goto fail2; + { + char xname[MAXMODNAME]; + + /* + * In case of error the entire module is gone, so we + * need to save its name for possible error report. + */ + + strlcpy(xname, mi->mi_name, MAXMODNAME); + error = kobj_affix(mod->mod_kobj, mi->mi_name); + if (error != 0) { + module_error("unable to affix module `%s', error %d", + xname, error); + goto fail2; + } } if (filedict) {