Questions about register_chrdev_region() in linux device driver

后端 未结 2 938
旧巷少年郎
旧巷少年郎 2021-01-05 01:16

I\'m learning about the registration of a kernel module using register_chrdev_region(dev_t from, unsigned count, const char * name);.

I notice that w

2条回答
  •  庸人自扰
    2021-01-05 01:39

    That will work because it's not actually necessary to allocate your device numbers up front. In fact, it's considered preferable by many kernel developers to use the dynamic (on-the-fly, as-needed) allocation function alloc_chrdev_region.

    Whether you do it statically up front or dynamically as needed, it is something you should do to avoid conflict with other device drivers which may have played by the rules and been allocated the numbers you're trying to use. Even if your driver works perfectly well without it, that won't necessarily be true on every machine or at any time in the future.

    The rules are there for a reason and, especially with low-level stuff, you are well advised to follow them.

    See here for more details on the set-up process.

提交回复
热议问题