Date: Thu, 4 Aug 2011 09:23:15 -0700 From: Garrett Cooper <yanegomi@gmail.com> To: freebsd-hackers@freebsd.org Subject: module_register_init fails, but driver is still loaded? Message-ID: <CAGH67wSfGxb0jrWcLYEimf_TSfsYR6A2_52vsyvbgTtEBM5TKQ@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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. Thanks! -Garrett /* bad_module.c */ #include <sys/param.h> #include <sys/kernel.h> #include <sys/module.h> #define MODULE_NAME "bad_module" static int load(module_t m, int what, void *arg) { return (EINVAL); } static moduledata_t bad_module_mod = { MODULE_NAME, &load, NULL, }; DECLARE_MODULE(bad_module, bad_module_mod, SI_SUB_KLD, SI_ORDER_ANY); MODULE_VERSION(bad_module, 1); /* Makefile */ KMOD= bad_module SRCS= bad_module.c .include <bsd.kmod.mk> $ sudo kldload ./bad_driver.ko $ dmesg | tail -n 1 module_register_init: MOD_LOAD (bad_module, 0xffffffff80a53000, 0) error 22 $ kldstat -v | grep bad_driver 5 1 0xffffffff80a53000 de bad_driver.ko $ sudo kldunload ./bad_driver.ko $ kldstat -v | grep bad_driver $
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGH67wSfGxb0jrWcLYEimf_TSfsYR6A2_52vsyvbgTtEBM5TKQ>