alloc_chrdev_region解析

来源:互联网 发布:阿里云企业备案流程图 编辑:程序博客网 时间:2024/06/08 05:28
/** * alloc_chrdev_region() - register a range of char device numbers * @dev: output parameter for first assigned number * @baseminor: first of the requested range of minor numbers * @count: the number of minor numbers required * @name: the name of the associated device or driver * * Allocates a range of char device numbers.  The major number will be * chosen dynamically, and returned (along with the first minor number) * in @dev.  Returns zero or a negative error code. */int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count,const char *name){struct char_device_struct *cd;//定义变量cd = __register_chrdev_region(0, baseminor, count, name); //0代表自动分配主设备号,次设备号,个数,名字if (IS_ERR(cd))//如果出错return PTR_ERR(cd);//返回*dev = MKDEV(cd->major, cd->baseminor);//改变新的设备号return 0;}

此函数相对于register_chrdev_region这个函数,优点在于不会出现重复的设备号,应该很少出错。

缺点未知

阅读全文
0 0