In the Linux kernel, most drivers can either be statically linked (embedded) to the kernel image itself, or created as dynamically loaded modules ( .ko ).
The MODULE macro is defined for the C file when it is compiled as part of the module, and undefined when it is created directly in the kernel.
The displayed code only defines os_driver_cleanup as a function to exit the module when it compiles as a module. However, this construct is not needed in modern kernel code; include/linux/init.h defines module_exit() as a macro whose implementation depends on #ifdef MODULE .
Basically, you should always provide an exit function and leave #ifdef around module_exit() . You should also mention the exit function with __exit , which will correctly control the inclusion of code for your module in the modular / non-modular case.
Here is an example of the correct initialization / exit code.
static int __init foo_init(void) { } static void __exit foo_cleanup(void) { } module_init(foo_init); module_exit(foo_cleanup);
source share