Date: Fri, 5 Aug 2011 19:21:39 +0400 From: Sergey Kandaurov <pluknet@gmail.com> To: Garrett Cooper <yanegomi@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: module_register_init fails, but driver is still loaded? Message-ID: <CAE-mSOJLta9pDNv=-QO9Lk8D-y%2BhT0P0Q=BGaAOF4JShVT6T_Q@mail.gmail.com> In-Reply-To: <CAGH67wSfGxb0jrWcLYEimf_TSfsYR6A2_52vsyvbgTtEBM5TKQ@mail.gmail.com> References: <CAGH67wSfGxb0jrWcLYEimf_TSfsYR6A2_52vsyvbgTtEBM5TKQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 4 August 2011 20:23, Garrett Cooper <yanegomi@gmail.com> wrote: > Hi hackers, > =A0 =A0I 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 =3D (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 =3D MOD_EVENT(mod, MOD_LOAD); if (error) { MOD_EVENT(mod, MOD_UNLOAD); + lf =3D 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) { --=20 wbr, pluknet
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAE-mSOJLta9pDNv=-QO9Lk8D-y%2BhT0P0Q=BGaAOF4JShVT6T_Q>