Skip to contentSkip to conversation

Added module parameters to the hello modlue

PATCH New Sumya Hoque 1 participant 1 message Feb 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Added module parameters to the hello modlue

I’ve followed these steps to add module parameters and capture the dmesg output:

I included the module.h header and used the module_param() macro to take the argument value as input from the command line. At runtime, insmod will take the input for the "name" variable. The default value is "World" if no input is provided.

Dmesg Output:

[27901.755598] Removing module... Goodbye World!
[27978.985148] Loading module... Hello Sumya
---
 linux_custom_modules/hello.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
linux_custom_modules/hello.c +4 -1
index a05727d605e3..178b717e1de1 100644
@@ -1,8 +1,11 @@
 #include <linux/module.h>
 #include <linux/printk.h>
+#include <linux/kernel.h>
+char *name = "World";
+module_param(name, charp, 0000);
 int hello(void)
 {
-        printk(KERN_INFO "Loading module... Hello World!\n");
+        printk(KERN_INFO "Loading module... Hello %s\n", name);
 
         return 0;
 }
Signature · 1 line
2.34.1