I have been trying to port few linux drivers and realized that there is substantial difference between kernel version 2.4 and 2.6 of linux.
In the 2.4 version of kernel, the module programming was as below -
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "Hi \n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Bye \n");
}
But, with the 2.6 version of kernel, the following has to be done for modules -
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int hi_init(void)
{
printk(KERN_ALERT "Hi \n");
return 0;
}
static void hi_exit(void)
{
printk(KERN_ALERT "Bye \n");
}
module_init(hi_init);
module_exit(hi_exit);
What is the advantage of such changes in Kernel 2.6 and Why was that change required in kernel 2.6 of linux ?
module_init
also exited in 2.4, mind you.It adds the necessary boilerplate to initialize the module and run the entry function when the module file is compiled into the kernel rather than as a module.
If you look at the definition of the new functions:
You'll see it ensures the right boilerplate is included so these special functions can correctly treated by the compiler. It's what the internal API of Linux does, it evolves if there are better ways of solving the problem.
One advantage is readability. cdrom_init() instantly tells you that it's the init() call for the cdrom driver.