<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML ><HEAD ><TITLE >Hello World (part 4): Licensing and Module Documentation</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="The Linux Kernel Module Programming Guide" HREF="index.html"><LINK REL="UP" TITLE="Hello World" HREF="c147.html"><LINK REL="PREVIOUS" TITLE="Hello World (part 3): The __init and __exit Macros" HREF="x281.html"><LINK REL="NEXT" TITLE="Passing Command Line Arguments to a Module" HREF="x354.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >The Linux Kernel Module Programming Guide</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x281.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 2. Hello World</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x354.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN321" ></A >2.5. Hello World (part 4): Licensing and Module Documentation</H1 ><P >If you're running kernel 2.4 or later, you might have noticed something like this when you loaded the previous example modules:</P ><TABLE BORDER="1" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="SCREEN" ># insmod hello-3.o Warning: loading hello-3.o will taint the kernel: no license See http://www.tux.org/lkml/#export-tainted for information about tainted modules Hello, world 3 Module hello-3 loaded, with warnings </PRE ></FONT ></TD ></TR ></TABLE ><P >In kernel 2.4 and later, a mechanism was devised to identify code licensed under the GPL (and friends) so people can be warned that the code is non open-source. This is accomplished by the <TT CLASS="FUNCTION" >MODULE_LICENSE()</TT > macro which is demonstrated in the next piece of code. By setting the license to GPL, you can keep the warning from being printed. This license mechanism is defined and documented in <TT CLASS="FILENAME" >linux/module.h</TT >.</P ><P >Similarly, <TT CLASS="FUNCTION" >MODULE_DESCRIPTION()</TT > is used to describe what the module does, <TT CLASS="FUNCTION" >MODULE_AUTHOR()</TT > declares the module's author, and <TT CLASS="FUNCTION" >MODULE_SUPPORTED_DEVICE()</TT > declares what types of devices the module supports.</P ><P >These macros are all defined in <TT CLASS="FILENAME" >linux/module.h</TT > and aren't used by the kernel itself. They're simply for documentation and can be viewed by a tool like <SPAN CLASS="APPLICATION" >objdump</SPAN >. As an exercise to the reader, try grepping through <TT CLASS="FILENAME" >linux/drivers</TT > to see how module authors use these macros to document their modules.</P ><DIV CLASS="EXAMPLE" ><A NAME="AEN351" ></A ><P ><B >Example 2-6. hello-4.c</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="PROGRAMLISTING" >/* hello-4.c - Demonstrates module documentation. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #define DRIVER_AUTHOR "Peiter Jay Salzman <p@dirac.org>" #define DRIVER_DESC "A sample driver" int init_hello_3(void); void cleanup_hello_3(void); static int init_hello_4(void) { printk(KERN_ALERT "Hello, world 4\n"); return 0; } static void cleanup_hello_4(void) { printk(KERN_ALERT "Goodbye, world 4\n"); } module_init(init_hello_4); module_exit(cleanup_hello_4); /* You can use strings, like this: */ MODULE_LICENSE("GPL"); // Get rid of taint message by declaring code as GPL. /* Or with defines, like this: */ MODULE_AUTHOR(DRIVER_AUTHOR); // Who wrote this module? MODULE_DESCRIPTION(DRIVER_DESC); // What does this module do? /* This module uses /dev/testdevice. The MODULE_SUPPORTED_DEVICE macro might be used in * the future to help automatic configuration of modules, but is currently unused other * than for documentation purposes. */ MODULE_SUPPORTED_DEVICE("testdevice");</PRE ></FONT ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x281.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x354.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Hello World (part 3): The <TT CLASS="LITERAL" >__init</TT > and <TT CLASS="LITERAL" >__exit</TT > Macros</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c147.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Passing Command Line Arguments to a Module</TD ></TR ></TABLE ></DIV ></BODY ></HTML >