Pages

Monday, November 9, 2015

insmod: ERROR: could not insert module hello.ko: Invalid parameters

I encountered this problem when I tried passing variables from command line using module_param for the first time.

This problem has a simple solution. The solution is that the assignment operator used to assign the value should not have any spaces before or after the operator.

I am using the following code :

#include <linux/module.h>   /* Needed by all modules */

#include <linux/kernel.h>   /* Needed for KERN_INFO */
#include <linux/moduleparam.h>

static int myvar = 1;
module_param(myvar, int , 0);
MODULE_PARM_DESC(myvar, "An integer");

static int __init init_hello(void)
{
        printk(KERN_INFO "Hello world 1.\n");
        printk(KERN_INFO "myvar is an integer: %d \n", myvar);
        return 0;
}

static void __exit cleanup_hello(void)
{
        printk(KERN_INFO "Goodbye world 1.\n");
}
module_init(init_hello);
module_exit(cleanup_hello);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sandesh Shrestha");

After I compile using make, I used the following command to insert the module:

ubuntu@sandesh:~/cpractice[00:44]$  sudo insmod hello.ko myvar=10

Please note that there are no spaces before and after the assignment operator.

No comments:

Post a Comment