LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 03-21-2008, 10:40 AM   #1
nabramovitz
LQ Newbie
 
Registered: Mar 2008
Location: Cupertino, CA
Posts: 2

Rep: Reputation: 0
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?
 
Old 03-25-2008, 03:03 AM   #2
ashok449
Member
 
Registered: Sep 2007
Location: noida
Distribution: suse
Posts: 63

Rep: Reputation: 16
cdev_alloc — allocate a cdev structure

look at below example

Code:
static struct cdev *a_cdev;
a_cdev = cdev_alloc();
this has nothing to do with cdev_del()


cdev_add() and cdev_del() are like kmalloc(), kfree()

cdev_add()
Code:
cdev_add — add a char device to the system 
int cdev_add ( struct cdev *   p,  
  dev_t   dev,  
  unsigned   count);
cdev_del()
Code:
cdev_del — remove a cdev from the system 

void cdev_del ( struct cdev *   p);

Hope this helps you...
 
Old 03-28-2008, 07:04 PM   #3
nabramovitz
LQ Newbie
 
Registered: Mar 2008
Location: Cupertino, CA
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
devicedrivers


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
file deleted, but no space freed kpachopoulos Linux - General 3 02-07-2008 10:43 AM
LXer: Two Linux remote desktop apps freed from their commercial ... LXer Syndicated Linux News 1 09-05-2006 11:01 AM
'Freeing Unused Kernel Memory: 224k Freed - Laptop Hangs nutnut Linux - Laptop and Netbook 1 10-21-2005 07:09 PM
Freeing unused kernel memory: 136k freed apenguinlinux Debian 8 08-08-2005 03:30 PM
Freeing unused kernel memory: 228k freed bodedeb Linux - General 8 10-28-2003 03:59 AM


All times are GMT -5. The time now is 03:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration