How does the cdev_alloc memory get freed up?
The cdev_alloc function uses kmalloc to allocate the cdev structure. Looking at the st and sg drivers, the cdev_del function does not seem to free the allocated memory with kmfree. I would not expect the cdev_del to free the memory since the cdev_del can also be used with cdev_init which uses preallocated memory.
So, if you use cdev_alloc, should kmfree be called to free the memory? If not, how does this allocated memory gets freed up when cdev_del is called? |
cdev_alloc — allocate a cdev structure
look at below example Code:
static struct cdev *a_cdev; cdev_add() and cdev_del() are like kmalloc(), kfree() cdev_add() Code:
cdev_add — add a char device to the system Code:
cdev_del — remove a cdev from the system Hope this helps you... |
cdev_alloc
Unfortunately, it does not because to create a cdev structure you are suppose to use either cdev_alloc or cdev_init. The cdev_alloc allocates the storage dynamically while the cdev_init is meant for statically defined structures. The cdev_add makes the character device available to the kernel and to users. The cdev_del call makes the character device unavailable for future use. If you use the cdev_alloc does cdev_del somehow know that the dynamic memory needs to be freed? I do not see how that would happen looking at the cdev_del code. What am I missing here? There does not seem be a cdev_free call which is what I would have expected.
|
All times are GMT -5. The time now is 09:59 AM. |