[firefly] [PATCH] Bring 'Hello World' kernel modules to the modern era.

Silviu-Mihai Popescu silviupopescu1990 at gmail.com
Sun Sep 9 16:57:31 EEST 2012


Updated the modules described in Chapter 2 of LDD3 to use pr_fmt()
and place initialization and cleanup routines in special code
sections.

Signed-off-by: Silviu-Mihai Popescu <silviupopescu1990 at gmail.com>
---
 misc-modules/hello.c  |   12 ++++++++----
 misc-modules/hellop.c |   12 ++++++++----
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/misc-modules/hello.c b/misc-modules/hello.c
index 85cd6d0..5e4b961 100644
--- a/misc-modules/hello.c
+++ b/misc-modules/hello.c
@@ -3,17 +3,21 @@
  */                                                    
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
+
 MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("LDD3, Silviu-Mihai Popescu");
+MODULE_DESCRIPTION("'Hello World' module in LDD3, with modern practices.");
 
-static int hello_init(void)
+static int __init hello_init(void)
 {
-	printk(KERN_ALERT "Hello, world\n");
+	pr_alert("Hello, world\n");
 	return 0;
 }
 
-static void hello_exit(void)
+static void __exit hello_exit(void)
 {
-	printk(KERN_ALERT "Goodbye, cruel world\n");
+	pr_alert("Goodbye, cruel world\n");
 }
 
 module_init(hello_init);
diff --git a/misc-modules/hellop.c b/misc-modules/hellop.c
index 88eaa67..526d7ab 100644
--- a/misc-modules/hellop.c
+++ b/misc-modules/hellop.c
@@ -4,8 +4,12 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/kernel.h>
 
 MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("LDD3, Silviu-Mihai Popescu");
+MODULE_DESCRIPTION("'Hello World with params' module in LDD3.\ 
+			with modern practices.");
 
 /*                                                        
  * These lines, although not shown in the book,           
@@ -23,17 +27,17 @@ static int howmany = 1;
 module_param(howmany, int, S_IRUGO);
 module_param(whom, charp, S_IRUGO);
 
-static int hello_init(void)
+static int __init hello_init(void)
 {
 	int i;
 	for (i = 0; i < howmany; i++)
-		printk(KERN_ALERT "(%d) Hello, %s\n", i, whom);
+		pr_alert("(%d) Hello, %s\n", i, whom);
 	return 0;
 }
 
-static void hello_exit(void)
+static void __exit hello_exit(void)
 {
-	printk(KERN_ALERT "Goodbye, cruel world\n");
+	pr_alert("Goodbye, cruel world\n");
 }
 
 module_init(hello_init);
-- 
1.7.2.5



More information about the firefly mailing list