#include
#include
dev_t scull_dev;
int scull_major;
int scull_minor;
static int scull_init(void)
{
int ret = 0;
ret = alloc_chrdev_region(&scull_dev, 0, 1,"scull");
if(ret){
printk(KERN_WARNING "error");
return ret;
}
scull_major = MAJOR(scull_dev);
scull_minor = MINOR(scull_dev);
printk(KERN_WARNING "alloc chrdev region %d %d", scull_major, scull_minor);
return 0;
}
static void scull_exit(void)
{
printk(KERN_WARNING "unregister chrdev region %d %d",MAJOR(scull_dev),MINOR(scull_dev));
unregister_chrdev_region(scull_dev,0);
}
module_init(scull_init);
module_exit(scull_exit);
卸载了模块后,cat /proc/devices 发现还有scull。
unregister_chrdev_region(scull_dev,0); <---------- 0改成1