module_register_init fails, but driver is still loaded?
Sergey Kandaurov
pluknet at gmail.com
Fri Aug 5 15:21:40 UTC 2011
On 4 August 2011 20:23, Garrett Cooper <yanegomi at 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.
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) {
--
wbr,
pluknet
More information about the freebsd-hackers
mailing list