Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys/kern If loading a built-in module fails, make ...



details:   https://anonhg.NetBSD.org/src/rev/b46489bd65b0
branches:  pgoyette-compat
changeset: 830608:b46489bd65b0
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Sep 04 11:31:11 2018 +0000

description:
If loading a built-in module fails, make sure we reset all the stuff
related to its pre-requisite modules.  Otherwise if we try to load it
again we will panic.

diffstat:

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

diffs (60 lines):

diff -r b2ad2ff4a95c -r b46489bd65b0 sys/kern/kern_module.c
--- a/sys/kern/kern_module.c    Tue Sep 04 11:25:53 2018 +0000
+++ b/sys/kern/kern_module.c    Tue Sep 04 11:31:11 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_module.c,v 1.130.2.13 2018/07/09 08:45:41 pgoyette Exp $  */
+/*     $NetBSD: kern_module.c,v 1.130.2.14 2018/09/04 11:31:11 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.13 2018/07/09 08:45:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_module.c,v 1.130.2.14 2018/09/04 11:31:11 pgoyette Exp $");
 
 #define _MODULE_INTERNAL
 
@@ -847,7 +847,7 @@
                areq = mod->mod_arequired + MAXMODDEPS;
                old = mod->mod_required;
                new = kmem_zalloc(areq * sizeof(module_t *), KM_SLEEP);
-               for (i = 0; i< mod->mod_arequired; i++)
+               for (i = 0; i < mod->mod_arequired; i++)
                        (*new)[i] = (*old)[i];
                mod->mod_required = new;
                if (old)
@@ -912,8 +912,10 @@
        /*
         * Initialize pre-requisites.
         */
+       KASSERT(mod->mod_required == NULL);
+       KASSERT(mod->mod_arequired == 0);
+       KASSERT(mod->mod_nrequired == 0);
        if (mi->mi_required != NULL) {
-               mod->mod_arequired = 0;
                for (s = mi->mi_required; *s != '\0'; s = p) {
                        if (*s == ',')
                                s++;
@@ -926,8 +928,9 @@
                                break;
                        alloc_required(mod);
                        error = module_do_builtin(mod, buf, &mod2, NULL);
-                       if (error != 0)
+                       if (error != 0) {
                                goto fail;
+                       }
                        (*mod->mod_required)[mod->mod_nrequired++] = mod2;
                }
        }
@@ -973,6 +976,9 @@
        if (mod->mod_required)
                kmem_free(mod->mod_required, mod->mod_arequired *
                    sizeof(module_t *));
+       mod->mod_arequired = 0;
+       mod->mod_nrequired = 0;
+       mod->mod_required = NULL;
        return error;
 }
 



Home | Main Index | Thread Index | Old Index