How to understand the macro __init?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 hi all

        in the kernel modules,we often use the macro __init.
if we only discuss the __init for functions.__init tells the
compiler to put  the function in a special section.and the
function are used once.So the code of this function should
be freed from the memory after the first call.

so i write a sample module:

#include <linux/module.h>
#include <linux/init.h>

void __init print_k(void)
{
    int k = 9;
    printk("<0>k = %d\n",k);
}

static int __init hello_init(void)
{
    printk("<0>hello kernel!\n");
    print_k();
    print_k();
    return 0;
}

static void __exit hello_exit(void)
{
    printk("<0>bye kernel!\n");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

i use the __init for function print_k.
in my opinion  after the fisrt invoking the print_k in the hello_init.
the memory of print_k will be freed,and the second invoking will
not be executed.but the result of second invoking is executing .

why?

Thanks in advance!
wanny
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux