Get name of kernel module in Driver Code - KBUILD_MODNAME
Kernel build system defines KBUILD_MODNAME automatically from each Makefile.
Following is the sample code which prints the name of module when loaded and unloaded.
Ouptut:
Following is the sample code which prints the name of module when loaded and unloaded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/kernel.h> | |
#include <linux/module.h> | |
MODULE_LICENSE("GPL"); | |
char *modname = __stringify(KBUILD_MODNAME); | |
static int test_hello_init(void) | |
{ | |
printk("%s: In init\n", __func__); | |
printk("%s: Module Name:%s Loaded\n", __func__, modname); | |
return 0; | |
} | |
static void test_hello_exit(void) | |
{ | |
printk("%s: In exit\n", __func__); | |
printk("%s: Module Name:%s Removed\n", __func__, modname); | |
} | |
module_init(test_hello_init); | |
module_exit(test_hello_exit); |
Comments
Post a Comment