'linux kernel driver, how to resize allocated character device region
I'm learning about linux kernel drivers and I am confused about device major/minor allocation. Especially the case in which I am not aware ahead of time of the number of devices I would like to manage.
Indeed, I know that we may allocate multiple devices at once dynamically with
alloc_chrdev_region (
&dev,
ALLOC_FIRST_MINOR,
ALLOC_COUNT,
DEV_NAME )
But I wonder about situations in which ALLOC_COUNT might not be obvious ahead of time.
Question
How do I re-size an allocated character device region ? Is it common practice to do so ?
Concerns
Large allocation drawbacks
Is there any drawback with taking a large/safe amount of minors and call cdev_init on a few of them only ?
Small allocation instead ?
If so, should I allocate small number of device first and then later allocate more if necessary later ? Is it something seen in the wild ? the last argument makes me think that I would be doing something wrong doing that.
What I Have Tried
Mutliple call to alloc_chred_region
I quickly run out of MAJOR numbers and I conclude this is not a very good solution
Multiple call to register_chred_region
I thought to make an initial call to alloc_chred_region which would give me a sentinel with a major dynamically allocated and then call at need register_chrdev_region to allocate more device number some time later. While much better that its counterpart, it doesn't fix any of the concerns.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
