驅動程式 - Linux Device Driver(LDD) - cdev_add()、register_chrdev()



Kernel v2.6以後,建議使用cdev()註冊Char Device,原因是register_chrdev()會直接註冊256個minor ID,不管使用者有無使用到,如下程式碼(v2.6.28):

int register_chrdev(unsigned int major, const char *name, const struct file_operations *fops)
{
    ...
    cd = __register_chrdev_region(major, 0, 256, name);
}