on 05/08/2011 18:21 Sergey Kandaurov said the following: > On 4 August 2011 20:23, Garrett Cooper <yaneg...@gmail.com> wrote: >> Hi hackers, >> I noticed that if anything fails while initializing a driver, the >> driver stays attached to the kernel as a module instead of being >> kicked when all references to the driver go to 0. Is this desired >> behavior (it doesn't seem like it, but I can see potential pros and >> cons of kicking the driver out of the kernel immediately when a >> failure state occurs)? I've seen this on 7.2 ~ 9-CURRENT. Example >> sourcecode and invocation attached below. > > Hi. > I have cooked something that might work, though I don't know how much > is it correct from locking & cleanup side. Can you try it? Anyway, in its > current form we cannot return error from module_register_init() because > it's usually called from SYSINIT, so kldload(8) will say nonsense: > can't load ./bad_module.ko: No error: 0.
Have you also accounted for a situation where multiple logical modules shared the same kernel loadable file? Especially when some modules load successfully while others fail. > Index: sys/kern/kern_module.c > =================================================================== > --- sys/kern/kern_module.c (revision 224471) > +++ sys/kern/kern_module.c (working copy) > @@ -112,6 +117,7 @@ module_register_init(const void *arg) > const moduledata_t *data = (const moduledata_t *)arg; > int error; > module_t mod; > + linker_file_t lf; > > mtx_lock(&Giant); > MOD_SLOCK; > @@ -123,12 +129,14 @@ module_register_init(const void *arg) > error = MOD_EVENT(mod, MOD_LOAD); > if (error) { > MOD_EVENT(mod, MOD_UNLOAD); > + lf = mod->file; > MOD_XLOCK; > module_release(mod); > MOD_XUNLOCK; > printf("module_register_init: MOD_LOAD (%s, %p, %p) error" > " %d\n", data->name, (void *)data->evhand, data->priv, > error); > + linker_release_module(NULL, NULL, lf); > } else { > MOD_XLOCK; > if (mod->file) { > > -- Andriy Gapon _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"