Freeing a dynamic struct cdev
If I allocate a struct cdev using cdev_alloc(), what function do I call to free it when I'm done with it?
Signature · 1 line
James C. Georgas <[email protected]>
Quoted 2 lines · On Sat, 06 Aug 2005 09:26:15 -0400 James C. Georgas wrote:
If I allocate a struct cdev using
cdev_alloc(), what function do I call to free it when I'm done with it?
Should be cdev_put(), which calls kobject_put(), which implements ref counting (using krefs), so that when the last reference is going away, the object will be removed.
---
~Randy
Quoted 11 lines · Randy.Dunlap
Quoted 2 lines · On Sat, 06 Aug 2005 09:26:15 -0400 James C. Georgas wrote:
If I allocate a struct cdev using
cdev_alloc(), what function do I call to free it when I'm done with it?Should be
cdev_put(), which callskobject_put(), which implements ref counting (using krefs), so that when the last reference is going away, the object will be removed.---
~Randy
cdev_put() is not an exported symbol in the fs/char_dev.c file. Should it be?
Signature · 1 line
James C. Georgas <[email protected]>
Quoted 10 lines · On Sat, 06 Aug 2005 15:26:18 -0400 James C. Georgas wrote:
Quoted 9 lines · Randy.Dunlap
Quoted 2 lines · On Sat, 06 Aug 2005 09:26:15 -0400 James C. Georgas wrote:
If I allocate a struct cdev using
cdev_alloc(), what function do I call to free it when I'm done with it?Should be
cdev_put(), which callskobject_put(), which implements ref counting (using krefs), so that when the last reference is going away, the object will be removed.
Quoted 5 lines
Quoted 2 lines
---
~Randy
cdev_put()is not an exported symbol in thefs/char_dev.cfile. Should it be?
Sorry about that, typo on my part. It's cdev_del().
---
~Randy
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Ok, I really blew it with that last post:
Quoted 5 lines
cdev_add()calls:kobj_map() kobject_get() [indirectly]
This is wrong. When I first looked at it, I saw:
cdev_add() -> kobj_map() -> exact_lock() -> cdev_get() -> kobject_get()
but exact_lock() isn't called here; it is only passed as a function pointer to kobj_map(), and so calling cdev_add() does /not/ increment the reference count of the struct cdev.
I guess what threw me for a loop here was that I was expecting separate
functions: one to undo cdev_add() and one to undo cdev_alloc(), but cdev_del() accomplishes both tasks in one function, with the kobj_unmap() part having no effect, if the cdev is not mapped at the time of the call.
Signature · 1 line
James C. Georgas <[email protected]>