All kernel module parameters are optional by default; the user may or may not explicitly pass them. But what if our project requires that the user must explicitly pass a value for a given kernel module parameter? We address this here: let's enhance our previous kernel module, creating another (ch5/modparams/modparams2), the key difference being that we set up an additional parameter called control_freak. Now, we require that the user must pass this parameter along at module insertion time:
- Let's set up the new module parameter in code:
static int control_freak;
module_param(control_freak, int, 0660);
MODULE_PARM_DESC(control_freak, "Set to the project's control level [1-5]. MANDATORY");
- How can we achieve this "mandatory passing"? Well, it's a bit of a hack really: just check at insertion time whether the value is the default (0, here). If so, then abort with an appropriate...