Handling module parameters
Similar to a user program, a kernel module can accept arguments from the command line. This allows us to dynamically change the behavior of the module according to the given parameters, which can help a developer not have to indefinitely change/compile the module during a test/debug session. In order to set this up, we should first declare the variables that will hold the values of command-line arguments and use the module_param()
macro on each of these. The macro is defined in include/linux/moduleparam.h
(this should be included in the code too – #include <linux/moduleparam.h>
) as follows:
module_param(name, type, perm);
This macro contains the following elements:
name
: The name of the variable used as the parameter.type
: The parameter's type (bool
,charp
,byte
,short
,ushort
,int
,uint
,long
, andulong
), wherecharp
stands for character pointer.perm
: This represents the/sys/module/<module>/parameters/<...