The problem is "insmod success", but seems the entry function "demo_init()" is not been executed. lsmod shows the module loaded successfully and no errors or warnings. However, I can't see "Hello, World!" after dmesg, and there is no device node "/dev/demo_device" and there is no class "/sys/class/demo_class". I'm not able to figure it out. Someone could help me, thanks. The kernel version is 3.10.86. The system Android.
This is my code:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/device.h>
int major;
static struct class *demo_class;
static struct device *demo_device;
static int demo_open(struct inode * inode, struct file * filp)
{
printk(KERN_ALERT "demo_open\n");
return 0;
}
static int demo_write(struct file * file, const char __user * buffer, size_t count, loff_t * ppos)
{
printk(KERN_ALERT "demo_write\n");
return 0;
}
static const struct file_operations demo_fops = {
.owner = THIS_MODULE,
.open = demo_open,
.write = demo_write,
};
static int __init demo_init(void) {
printk(KERN_ALERT "Hello, World!\n");
major = register_chrdev(0, "demo_drv", &demo_fops);
demo_class = class_create(THIS_MODULE, "demo_class");
demo_device = device_create(demo_class, NULL, MKDEV(major, 0), NULL, "demo_device");
return 0;
}
static void __exit demo_exit(void) {
printk(KERN_ALERT "Goodbye, World!\n");
unregister_chrdev(major, "demo_drv");
device_unregister(demo_device);
class_destroy(demo_class);
}
module_init(demo_init);
module_exit(demo_exit);
MODULE_VERSION("0.01");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("A simple example Linux module.");