Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys/kern Clean up the EXIST paths (module and/or a...



details:   https://anonhg.NetBSD.org/src/rev/9f279aad6d90
branches:  pgoyette-compat
changeset: 830422:9f279aad6d90
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Mar 11 11:47:45 2018 +0000

description:
Clean up the EXIST paths (module and/or alias already exists) and make
sure we always return a pointer to the duplicate.

diffstat:

 sys/kern/kern_module.c |  34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diffs (96 lines):

diff -r 11ad87e5ea9a -r 9f279aad6d90 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Sun Mar 11 09:34:59 2018 +0000
+++ b/sys/kern/kern_module.c    Sun Mar 11 11:47:45 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_module.c,v 1.130.2.3 2018/03/11 08:32:21 pgoyette Exp $   */
+/*     $NetBSD: kern_module.c,v 1.130.2.4 2018/03/11 11:47:45 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.130.2.3 2018/03/11 08:32:21 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.130.2.4 2018/03/11 11:47:45 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -671,9 +671,10 @@
        aliasp = *mod->mod_info->mi_aliases;
        if (aliasp == NULL)
                return 0;
-       while (*aliasp)
+       while (*aliasp) {
                if (strcmp(*aliasp++, name) == 0)
                        return 1;
+       }
        return 0;
 }
 
@@ -690,11 +691,10 @@
        KASSERT(kernconfig_is_held());
 
        TAILQ_FOREACH(mod, &module_list, mod_chain) {
-               if (strcmp(mod->mod_info->mi_name, name) == 0) {
+               if (strcmp(mod->mod_info->mi_name, name) == 0)
                        break;
                if (module_alias_lookup(name, mod))
                        break;
-               }
        }
 
        return mod;
@@ -855,13 +855,17 @@
        }
 
        /*
-        * Retrieve that none of the module's aliases already exist
+        * Confirm that none of the module's aliases already exist
         */
 
        if ((aliasp = *mod->mod_info->mi_aliases) != NULL) {
-               while (*aliasp)
-                       if (module_lookup(*aliasp++) != NULL)
+               while (*aliasp) {
+                       if ((mod2 = module_lookup(*aliasp++)) != NULL) {
+                               if (modp != NULL)
+                                       *modp = mod2;
                                return EEXIST;
+                       }
+               }
        }
        /*
         * Try to initialize the module.
@@ -1084,6 +1088,8 @@
                        module_error("module with name `%s' already loaded",
                            mod2->mod_info->mi_name);
                        error = EEXIST;
+                       if (modp != NULL)
+                               *modp = mod2;
                        goto fail;
                }
        }
@@ -1171,13 +1177,19 @@
        /*
         * One last check for duplicate module name/alias
         */
-       if ((aliasp = *mod->mod_info->mi_aliases) != NULL)
-               while (*aliasp != NULL)
-                       if (module_lookup(*aliasp) != NULL) {
+       if ((aliasp = *mod->mod_info->mi_aliases) != NULL) {
+               while (*aliasp != NULL) {
+                       if ((mod2 = module_lookup(*aliasp)) != NULL) {
                                module_error("Module `%s' alias `%s' already "
                                    "exists", mod->mod_info->mi_name, *aliasp);
+                               error = EEXIST;
+                               if (modp != NULL)
+                                       *modp = mod2;
                                goto fail;
                        }
+                       aliasp++;
+               }
+       }
 
        prev_active = module_active;
        module_active = mod;



Home | Main Index | Thread Index | Old Index