Reputation: 67
I have created a simple kernel module named mymodule.c
. After I insert it:
insmod mymodule.ko param_int=0x100
it gets loaded and it prints the correct value in logs. I can also see the folder /sys/module/mymodule/
getting created. But I don't see the parameters folder getting created inside /sys/module/mymodule/
What am I doing wrong?
#include <linux/module.h>
#include <linux/init.h>
static int param_int = 0xBABE;
module_param(param_int, int, 0);
MODULE_PARM_DESC(param_int, "Pass any integer from insmod, it will be printed");
static int __init ch03_lab1_init(void)
{
pr_info("Chapter 03 Lab1\n");
pr_info("param_int = 0x%x\n",param_int);
return 0;
}
static void __exit ch03_lab1_exit(void)
{
pr_info("Chapter 03 Lab1 Exit\n");
}
module_init(ch03_lab1_init);
module_exit(ch03_lab1_exit);
MODULE_AUTHOR("SATHYA");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("WLDD Chapter3 Lab 1 example");
MODULE_VERSION("2.0");
Upvotes: 2
Views: 719
Reputation: 1935
Here's your problem:
module_param(param_int, int, 0);
The last argument to that module_param
macro is the permissions for the variable in sysfs. Since you've specified zero there, the parameter isn't exported.
Change this to something like:
module_param(param_int, int, S_IRUGO | S_IWUSR);
And you should have it appear as expected.
Upvotes: 4
Reputation: 10947
Entries in sys/ must be created explicitly in the module code:
static DEVICE_ATTR(<name>, 0644, show_data, store_data);
static ssize_t store_data (struct device *dev, \
struct device_attribute *attr, \
const char *buf, size_t len)
{
struct platform_device *pdev = to_platform_device(dev);
unsigned int value = simple_strtoul (buf, NULL, 10);
/* ... */
return strnlen(buf, PAGE_SIZE);
}
static ssize_t show_data (struct device *dev, \
struct device_attribute *attr, \
char *buf)
{
struct platform_device *pdev = to_platform_device(dev);
unsigned int value = ...;
return snprintf(buf, PAGE_SIZE, "%u\n", value);
}
Upvotes: 0