Module parameters.
[cascardo/kernel/samples/01.hello/.git] / hello.c
diff --git a/hello.c b/hello.c
index dca8626..b5c0a6d 100644 (file)
--- a/hello.c
+++ b/hello.c
@@ -14,19 +14,26 @@ MODULE_LICENSE("GPL");
 #define SUBJECT "world"
 #endif
 
+static char *subject = SUBJECT;
+
+/* Define subject as a char pointer parameter. */
+module_param(subject, charp, 0664);
+/* Parameter description. */
+MODULE_PARM_DESC(subject, "Subject to say hello to.");
+
 /* Our init function: returns 0 if successfull, an error code, otherwise. */
-static int hello_init(void)
+static int __init hello_init(void)
 {
        /* printk is just like printf, but without floating point support. */
-       printk(KERN_ALERT "Hello, " SUBJECT "!\n");
+       printk(KERN_ALERT "Hello, %s!\n", subject);
        return 0;
 }
 
 /* Our exit function: static is good, so we do not pollute namespace. */
-static void hello_exit(void)
+static void __exit hello_exit(void)
 {
        /* KERN_ALERT is a string macro prepended to our message. */
-       printk(KERN_ALERT "Goodbye, cruel " SUBJECT "!\n");
+       printk(KERN_ALERT "Goodbye, cruel %s!\n", subject);
 }
 
 /* Here, we declare our module init and exit functions. */