{"id":7143,"date":"2022-02-03T08:32:14","date_gmt":"2022-02-03T08:32:14","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=7143"},"modified":"2023-09-12T11:30:56","modified_gmt":"2023-09-12T06:00:56","slug":"linux-device-driver-programming-lecture-18-__init-and-__exit-macros","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/","title":{"rendered":"Linux Device Driver Programming Lecture 18: __init and __exit macros"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px;\"><span style=\"color: #000080;\"><b>__init and __exit macros<\/b><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this article, let&#8217;s explore init and exit macros. These are called as function or variables section attributes(shown in Figure 1).<\/span><\/p>\n<figure id=\"attachment_7146\" aria-describedby=\"caption-attachment-7146\" style=\"width: 655px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-7146\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-1-2.png\" alt=\"Figure 1. Function section attributes\" width=\"655\" height=\"244\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png 655w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2-300x112.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2-600x224.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2-120x45.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2-500x186.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2-200x75.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2-400x149.png 400w\" sizes=\"(max-width: 655px) 100vw, 655px\" \/><figcaption id=\"caption-attachment-7146\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Function section attributes<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<ul class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"color: #000000;\"><code>__init<\/code> and <code>__exit<\/code> macros are C macros used in the Linux kernel.<\/span><\/li>\n<li><span style=\"color: #000000;\">These macros are defined in <code>LINUX_SRC\/include\/linux\/init.h<\/code>. <span style=\"font-weight: 400;\">You can open the init.h file, and you will find these macros.<\/span><\/span><\/li>\n<li><span style=\"color: #000000;\">They are compiler directives or attributes.<\/span><\/li>\n<\/ul>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">You can see above there are just C macros and which expand to a something called compiler directive.&nbsp;<\/span><span style=\"font-weight: 400;\">These are compiler directives, or you can also call it as compiler attributes (shown in Figure 1).<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">For example, if you take the first case __init, which expands into __section(.init.text). Here, this is called as a compiler directive, which directs the compiler to keep data or code in an output section called &#8220;init.&#8221;&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">When you use this __init macro with any function, then that function code will be placed in a section called &#8220;.init&#8221; in the final kernel image.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Similarly, __exit is also another C macro, which expands to __section(.exit.text) compiler directive, which directs the compiler to keep data or code in an output section called &#8220;exit.&#8221;&nbsp;<\/span><span style=\"font-weight: 400;\">__init, and __exit makes sense only for static modules.<\/span><\/span><\/p>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>Purpose of <code>__init<\/code> Macro:<\/strong><\/span><\/p>\n<ul class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"color: #000000;\"><code>__init<\/code> is a C macro that expands into a compiler directive, directing the compiler to place code in the <code>.init<\/code> section of the final ELF image of the Linux kernel.<\/span><\/li>\n<li><span style=\"color: #000000;\">The <code>.init<\/code> section is freed from memory by the kernel during boot after initialization functions are executed.<\/span><\/li>\n<li><span style=\"color: #000000;\">It is mainly used for static modules.<\/span><\/li>\n<li><span style=\"color: #000000;\">Built-in drivers, which cannot be unloaded, do not need to keep references to their init functions in memory.<\/span><\/li>\n<\/ul>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_7147\" aria-describedby=\"caption-attachment-7147\" style=\"width: 577px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-7147 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-2-3.png\" alt=\"Figure 2. Init and Exit functions- Linux kernel development\" width=\"577\" height=\"239\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-3.png 577w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-3-300x124.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-3-120x50.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-3-500x207.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-3-200x83.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-3-400x166.png 400w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><figcaption id=\"caption-attachment-7147\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Init and Exit functions<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">For example, this is the init function(in Figure 2). <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">If this module is a built-in module, then this function will be called only one time, that is, during the boot time. <\/span><\/span><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And once this function finishes, then why would you need this function. Because it&#8217;s a static function, no one is going to call it. Don&#8217;t you think it&#8217;s better to remove the memory occupied by this function code, the kernel can remove it from the memory, which will save some memory, because there are 100 thousand built-in modules. <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Removing some memory for 100 modules would be huge. The kernel is going to save a lot of runtime memory. <\/span><span style=\"font-weight: 400;\">That&#8217;s why __init is a technique by using that we push that function into a init section, a separate section, which a kernel can free later.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Using __init macro is a technique, when used with a&nbsp; function, the kernel will free the code memory of that function after its execution. And also, remember that it is an optional one.&nbsp;<\/span><span style=\"font-weight: 400;\">If you omit that, then no problem. You don&#8217;t see any compilation, warnings, or errors. You can omit that.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Similarly, you can use __initdata with variables that will be dropped after the initialization.__init is for code or for function,&nbsp; __initdata is for variables, init variables.<\/span><\/p>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>Purpose of <code>__exit<\/code> Macro:<\/strong><\/span><\/p>\n<ul class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"color: #000000;\">For built-in modules, cleanup functions are not required.<\/span><\/li>\n<li><span style=\"color: #000000;\">When <code>__exit<\/code> is used with a cleanup function, the kernel build system excludes those functions during the build process.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>__exit<\/code> acts as a marker for the build system to exclude cleanup functions from the final kernel image.<\/span><\/li>\n<\/ul>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Usage Example:<\/strong><\/span><\/p>\n<ul>\n<li style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #000000;\">Consider three static modules: <code>module1.c<\/code>, <code>module2.c<\/code>, and <code>module3.c<\/code>.<\/span><\/li>\n<\/ul>\n<figure id=\"attachment_7148\" aria-describedby=\"caption-attachment-7148\" style=\"width: 703px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-7148 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-3-2.png\" alt=\"Figure 3. Init function\u2019s modules explanation- Linux kernel development\" width=\"703\" height=\"384\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2.png 703w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2-300x164.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2-600x328.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2-120x66.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2-500x273.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2-200x109.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-2-400x218.png 400w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><figcaption id=\"caption-attachment-7148\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Init function\u2019s modules explanation<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s say module1.c&#8217;s init function is m1 init function, module2.c&#8217;s init function is m2&nbsp;<\/span><span style=\"font-weight: 400;\">init function, and module3.c&#8217;s init function is m3 init function. Out of these 3 init functions, m1 init function and m2 init functions are tagged with init macros.<\/span><\/span><\/p>\n<ul class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #000000;\"><code>module1.c<\/code> and <code>module2.c<\/code> have init functions tagged with <code>__init<\/code>.<\/span><\/li>\n<li data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #000000;\">During kernel build, all three modules become part of the final kernel image.<\/span><\/li>\n<li data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #000000;\">A new <code>.init<\/code> section is created in the final image, and <code>m1_init_function<\/code> and <code>m2_init_function<\/code> are placed in this section.<\/span><\/li>\n<li data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #000000;\">The kernel calls <code>m1_init_function<\/code> and <code>m2_init_function<\/code> during boot and frees the memory occupied by the <code>.init<\/code> section since these functions won&#8217;t be executed again.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>m3_init_function<\/code> is not tagged with <code>__init<\/code>, so it remains in the <code>.text<\/code> region and consumes memory throughout kernel runtime.<\/span><\/li>\n<li><span style=\"color: #000000;\">All functions marked with <code>__exit<\/code> are dropped by the kernel build system and are not part of the final image.<\/span><\/li>\n<\/ul>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 20px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Conclusion:<\/strong><\/span><\/p>\n<ul class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"color: #000000;\">The use of <code>__init<\/code> and <code>__exit<\/code> macros helps optimize memory usage in the Linux kernel.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>__init<\/code> is used for code\/functions, while <code>__exit<\/code> is used for cleanup functions.<\/span><\/li>\n<li><span style=\"color: #000000;\">These macros are optional but can significantly reduce memory consumption for certain modules.<\/span><\/li>\n<\/ul>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the following article, I am going to cover <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"http:\/\/fastbitlab.com\/linux-device-driver-programming-lecture-19-lkm-entry-point-registration-and-other-macros\/\" target=\"_blank\" rel=\"noopener\">Linux Kernel module entry points registration<\/a>.<\/span>&nbsp;<\/span><\/p>\n<p class=\"\" style=\"font-family: 'Roboto Slab'; font-weight: 400; font-size: 18px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #993366;\">Get the Full Course on Linux device Driver <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.udemy.com\/course\/linux-device-driver-programming-using-beaglebone-black\/\">Here<\/a>.<\/span><\/span><\/strong><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 28px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">Click here: <\/span><span style=\"color: #3366ff;\"><a style=\"color: #3366ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\">https:\/\/fastbitlab.com\/course1<\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; __init and __exit macros &nbsp; &nbsp; In this article, let&#8217;s explore init and exit macros. These are called as function or variables section attributes(shown in Figure 1). &nbsp; __init and __exit macros are C macros used in the Linux kernel. These macros are defined in LINUX_SRC\/include\/linux\/init.h. You can open the init.h file, and you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7146,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[18],"class_list":["post-7143","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-linux-device-driver-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>__init and __exit Macros in Linux Kernel Development<\/title>\n<meta name=\"description\" content=\"init and exit macros. Explore the significance of __init and __exit macros in Linux kernel development. Learn how these C macros optimize\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"__init and __exit Macros in Linux Kernel Development\" \/>\n<meta property=\"og:description\" content=\"init and exit macros. Explore the significance of __init and __exit macros in Linux kernel development. Learn how these C macros optimize\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-03T08:32:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-12T06:00:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"655\" \/>\n\t<meta property=\"og:image:height\" content=\"244\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Linux Device Driver Programming Lecture 18: __init and __exit macros\",\"datePublished\":\"2022-02-03T08:32:14+00:00\",\"dateModified\":\"2023-09-12T06:00:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/\"},\"wordCount\":818,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-2.png\",\"keywords\":[\"Linux Device Driver Programming Tutorial\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/\",\"name\":\"__init and __exit Macros in Linux Kernel Development\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-2.png\",\"datePublished\":\"2022-02-03T08:32:14+00:00\",\"dateModified\":\"2023-09-12T06:00:56+00:00\",\"description\":\"init and exit macros. Explore the significance of __init and __exit macros in Linux kernel development. Learn how these C macros optimize\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-2.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-2.png\",\"width\":655,\"height\":244,\"caption\":\"Figure 1. Function section attributes\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Device Driver Programming Lecture 18: __init and __exit macros\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"__init and __exit Macros in Linux Kernel Development","description":"init and exit macros. Explore the significance of __init and __exit macros in Linux kernel development. Learn how these C macros optimize","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/","og_locale":"en_US","og_type":"article","og_title":"__init and __exit Macros in Linux Kernel Development","og_description":"init and exit macros. Explore the significance of __init and __exit macros in Linux kernel development. Learn how these C macros optimize","og_url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-02-03T08:32:14+00:00","article_modified_time":"2023-09-12T06:00:56+00:00","og_image":[{"width":655,"height":244,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Linux Device Driver Programming Lecture 18: __init and __exit macros","datePublished":"2022-02-03T08:32:14+00:00","dateModified":"2023-09-12T06:00:56+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/"},"wordCount":818,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png","keywords":["Linux Device Driver Programming Tutorial"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/","url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/","name":"__init and __exit Macros in Linux Kernel Development","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png","datePublished":"2022-02-03T08:32:14+00:00","dateModified":"2023-09-12T06:00:56+00:00","description":"init and exit macros. Explore the significance of __init and __exit macros in Linux kernel development. Learn how these C macros optimize","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-2.png","width":655,"height":244,"caption":"Figure 1. Function section attributes"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-18-__init-and-__exit-macros\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Device Driver Programming Lecture 18: __init and __exit macros"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=7143"}],"version-history":[{"count":4,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7143\/revisions"}],"predecessor-version":[{"id":15900,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7143\/revisions\/15900"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/7146"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=7143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=7143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=7143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}