[PATCH] Added module parameters to the hello modlue

Sumya Hoque
2025-02-12T04:40:40Z

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

Signed-off-by: Sumya Hoque <sumyahoque2012@gmail.com>
---
linux_custom_modules/hello.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/linux_custom_modules/hello.c b/linux_custom_modules/hello.c
index a05727d605e3..178b717e1de1 100644
--- a/linux_custom_modules/hello.c
+++ b/linux_custom_modules/hello.c
@@ -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;
}
--
2.34.1