Questions about register_chrdev_region() in linux device driver

后端 未结 2 937
旧巷少年郎
旧巷少年郎 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.

    0 讨论(0)
  • 2021-01-05 01:40

    If the major number for your devices clash with any other device already in use, then the driver won't have the allocation done.

    If you have already tested which major number is free and used it, it might generally not throw up an error and you will face no problem as u load the driver.

    But if you run on various systems and if the major number is already captured and used by some other system., Then your driver loading can fail.

    Its always better to use dynamic allocation !!

    0 讨论(0)
提交回复
热议问题