How to Figure Out What Is Using a Linux Kernel Module

How to get use count from Linux kernel module?

module_refcount() will give you the use count of the module passed.

How to view information about a newly loaded external Linux kernel module?

From the man page:

modinfo extracts information from the Linux Kernel modules given on the command line. If the module name is not a filename, then the /lib/modules/version directory is searched, as is also done by
modprobe(8) when loading kernel modules.

So it looks like this command just uses the kernel module files to get this information, so you can either run:

modinfo hello.ko

or you could put your kernel module in the /lib/modules/version/ directory

Get Linux Kernel module name from current module

Inside the code of the kernel module, THIS_MODULE points to the structure representing this module. You may use name field of this structure for extract the current module name:

printk("Current module name: %s\n", THIS_MODULE->name);

If your code could be compiled (depending on configuration) either as a module or as a part of the kernel, then in the latter case THIS_MODULE will be NULL, so you cannot access its fields. For such code you could use module_name macro instead:

printk("Current module name: %s\n", module_name(THIS_MODULE));

Within the kernel core code (not a module) the macro is expanded to the string "kernel".



Related Topics



Leave a reply



Submit