summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_linker.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-06-13 19:45:08 +0000
committerjhb <jhb@FreeBSD.org>2006-06-13 19:45:08 +0000
commitbaafd575e63555a97bea85e6b067aec2fee97941 (patch)
tree3eeb9216a81d517707fd5e4dbfc46ac6594bd616 /sys/kern/kern_linker.c
parent35917647ed66746e3c838add29c86d9153593edb (diff)
downloadFreeBSD-src-baafd575e63555a97bea85e6b067aec2fee97941.zip
FreeBSD-src-baafd575e63555a97bea85e6b067aec2fee97941.tar.gz
Handle the simple case of just dropping a reference near the start of
linker_file_unload() instead of in the middle of a bunch of code for the case of dropping the last reference to improve readability and sanity. While I'm here, remove pointless goto's that were just jumping to a return statement.
Diffstat (limited to 'sys/kern/kern_linker.c')
-rw-r--r--sys/kern/kern_linker.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c
index 78ff9e4..627b7a4 100644
--- a/sys/kern/kern_linker.c
+++ b/sys/kern/kern_linker.c
@@ -487,8 +487,6 @@ linker_file_unload(linker_file_t file, int flags)
struct common_symbol *cp;
int error, i;
- error = 0;
-
/* Refuse to unload modules if securelevel raised. */
if (securelevel > 0)
return (EPERM);
@@ -499,35 +497,37 @@ linker_file_unload(linker_file_t file, int flags)
#endif
KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs));
- if (file->refs == 1) {
- KLD_DPF(FILE, ("linker_file_unload: file is unloading,"
- " informing modules\n"));
+
+ /* Easy case of just dropping a reference. */
+ if (file->refs > 1) {
+ file->refs--;
+ return (0);
+ }
+
+ KLD_DPF(FILE, ("linker_file_unload: file is unloading,"
+ " informing modules\n"));
+
+ /*
+ * Inform any modules associated with this file.
+ */
+ MOD_XLOCK;
+ for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
+ next = module_getfnext(mod);
+ MOD_XUNLOCK;
/*
- * Inform any modules associated with this file.
+ * Give the module a chance to veto the unload.
*/
- MOD_XLOCK;
- for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
- next = module_getfnext(mod);
- MOD_XUNLOCK;
-
- /*
- * Give the module a chance to veto the unload.
- */
- if ((error = module_unload(mod, flags)) != 0) {
- KLD_DPF(FILE, ("linker_file_unload: module %p"
- " vetoes unload\n", mod));
- goto out;
- } else
- MOD_XLOCK;
- module_release(mod);
+ if ((error = module_unload(mod, flags)) != 0) {
+ KLD_DPF(FILE, ("linker_file_unload: module %p"
+ " vetoes unload\n", mod));
+ return (error);
}
- MOD_XUNLOCK;
- }
- file->refs--;
- if (file->refs > 0) {
- goto out;
+ MOD_XLOCK;
+ module_release(mod);
}
+ MOD_XUNLOCK;
+
for (ml = TAILQ_FIRST(&found_modules); ml; ml = nextml) {
nextml = TAILQ_NEXT(ml, link);
if (ml->container == file) {
@@ -566,8 +566,7 @@ linker_file_unload(linker_file_t file, int flags)
file->filename = NULL;
}
kobj_delete((kobj_t) file, M_LINKER);
-out:
- return (error);
+ return (0);
}
int
OpenPOWER on IntegriCloud