我写的驱动模块, 用 device_create来建立设备文件,但ls /dev找不到相对应的myalloc设备,请大家帮忙看一下
int __init memory_init(void)
{
int res;
int devno = MKDEV(MEM_MAJOR, 0);
mem_spvm = (char *)vmalloc(MEM_MALLOC_SIZE);
if (mem_spvm == NULL)
printk(KERN_INFO"vmalloc failed!
");
else
printk(KERN_INFO"vmalloc successfully! addr=0x%x
", (unsigned int)mem_spvm);
mem_cdev = cdev_alloc();
if (mem_cdev == NULL)
{
printk(KERN_INFO"cdev_alloc failed!
");
return 0;
}
cdev_init(mem_cdev, &mem_fops);
mem_cdev->owner = THIS_MODULE;
mem_cdev->ops = &mem_fops;
res = cdev_add(mem_cdev, devno, 1);
if (res)
{
cdev_del(mem_cdev);
mem_cdev = NULL;
printk(KERN_INFO"cdev_add error
");
}
else
{
printk(KERN_INFO"cdev_add ok
");
}
/* creating your own class */
my_class = class_create(THIS_MODULE, "myalloc");
if(IS_ERR(my_class)) {
printk("Err: failed in creating class.
");
return -1;
}
/* register your own device in sysfs, and this will cause udevd to create corresponding device node */
device_create(my_class, NULL, MKDEV(MEM_MAJOR,0), NULL, "myalloc", 0); return 0;
}
|