From: Thadeu Lima de Souza Cascardo Date: Sun, 6 Dec 2009 02:07:03 +0000 (-0200) Subject: Module parameters. X-Git-Tag: v1.9.0 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fkernel%2Fsamples%2F01.hello%2F.git;a=commitdiff_plain;h=9b2e34b7ae5d50e8e2a20bb7f74270834fabe2a8 Module parameters. --- diff --git a/hello.c b/hello.c index 327ee34..b5c0a6d 100644 --- a/hello.c +++ b/hello.c @@ -14,11 +14,18 @@ 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 __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; } @@ -26,7 +33,7 @@ static int __init hello_init(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. */